473,734 Members | 2,511 Online

I am working on a new library for my own use that
would allow me to use SI Units and to convert
them back and forth with ease.

However, While I have been working on operator

If I want to be able to simplify units through
operators, I end up with inter-dependant classes.

1 class Area {
2 public:
4 Area& operator+=(cons t Area& addend);
5 Area operator*(const float scalar);
6 Area operator*(const int scalar);
8 };
9
10 class Length {
11 public:
13 Length& operator+=(cons t Length& addend);
14 Length operator*(const float scalar);
15 Length operator*(const int scalar);
16 Area operator*(const Length& multiplier);
17 };

This tells me that I cannot have no type on the "Length" token on line
7.

What am I to do?

Aug 23 '05 #1
9 2206
Sp************* *@gmail.com wrote:

I am working on a new library for my own use that
would allow me to use SI Units and to convert
them back and forth with ease.

However, While I have been working on operator

If I want to be able to simplify units through
operators, I end up with inter-dependant classes.

1 class Area {
2 public:
4 Area& operator+=(cons t Area& addend);
5 Area operator*(const float scalar);
6 Area operator*(const int scalar);
8 };
9
10 class Length {
11 public:
13 Length& operator+=(cons t Length& addend);
14 Length operator*(const float scalar);
15 Length operator*(const int scalar);
16 Area operator*(const Length& multiplier);
17 };

This tells me that I cannot have no type on the "Length" token on line
7.

What am I to do?

use a forward declaration:

class Length; // forward declare that somewhere there is indeed a class
// called 'Length'

class Area {
public:
.....

// now that the compiler knows that 'Length' is not a typo, but
// indeed is the name of a class, this is valid
};

class Length {
public:
....
};
--
Karl Heinz Buchegger
Aug 23 '05 #2
Sp************* *@gmail.com wrote:
I am working on a new library for my own use that
would allow me to use SI Units and to convert
them back and forth with ease.

However, While I have been working on operator

If I want to be able to simplify units through
operators, I end up with inter-dependant classes.

1 class Area {
2 public:
4 Area& operator+=(cons t Area& addend);
5 Area operator*(const float scalar);
6 Area operator*(const int scalar);
8 };
9
10 class Length {
11 public:
13 Length& operator+=(cons t Length& addend);
14 Length operator*(const float scalar);
15 Length operator*(const int scalar);
16 Area operator*(const Length& multiplier);
17 };
First of all, take a look at this:
---------------------------------------------
class Area {
public:
Area operator*(const float scalar);
Area operator*(const int scalar);
Length operator/(const Length& addend); //***** line 7
};

class Length {
public:
Length operator*(const float scalar);
Length operator*(const int scalar);
Area operator*(const Length& multiplier);
};
---------------------------------------------
Now, how much nicer is this text compared to yours? It looks and
reads as the C++ code it is.
This tells me that I cannot have no type on the "Length" token on line
7.

What am I to do?

Define both operator/ in Area and operator* in Length as non-members
_after_ both classes. They should be non-members, anyway, since they
don't change the members. They could be friends (although I am sure they
don't need to be).

V
Aug 23 '05 #3
First of All, Karl, thank you. Somehow I did not t=know that forward
declaration of classes was possible.

And secondly, Victor, I see absolutely no benefeit to your style.

Aug 23 '05 #4
Otac0n wrote:
First of All, Karl, thank you. Somehow I did not t=know that forward
declaration of classes was possible.

And secondly, Victor, I see absolutely no benefeit to your style.

Aug 23 '05 #5
Otac0n wrote:
First of All, Karl, thank you. Somehow I did not t=know that forward
declaration of classes was possible.

And secondly, Victor, I see absolutely no benefeit to your style.

The benefit is that one can easily cut and past the code -- no need to get
rid of the line numbers before you try to compile.
Best

Kai-Uwe Bux
Aug 23 '05 #6
This was not executable code, and it needed a line number.

In this case, the style used is moot.

Aug 23 '05 #7
Sp************* *@gmail.com wrote:
I am working on a new library for my own use that
would allow me to use SI Units and to convert
them back and forth with ease.

[snip]

You might be interested in the alternative approach to dimensional
analysis from the Boost MPL tutorial:

http://boost.org/libs/mpl/doc/tutori...-analysis.html

Cheers! --M

Aug 23 '05 #8
hi,

i think what victor was trying to say that the code should be in c++
because may of the people sititng out and helping ocassionaly paste the
code into their environment and
then check out the problem. so if the code is pure C++ it is better if
the code can be pasted and directly be runable.

thanks
rt

Aug 24 '05 #9
Otac0n wrote:

This was not executable code, and it needed a line number.

In this case, the style used is moot.

For you: yes.
For us: no.

*We* are the ones who frequently cut&paste things *from* a
newsgroup posting into our editors to figure out what the
OP could have ment and what error messages he gets.

So making this job as easy as possible for us increases your
chances of getting an answer tremendously. In this case it
doesn't even mean more work for you: Just cut&paste the code
from your editor and mark the line in question. Is that asking
for to much?

--
Karl Heinz Buchegger