J
JustSomeGuy
I have two object types ClassA and ClassB
class ClassA {
public:
int data;
operator ClassB()
{
ClassB b;
b.data = data + 1;
return (b);
}
};
class ClassB {
public:
int data;
operator ClassA()
{
ClassB b;
b.data = data - 1;
return(b);
}
}
So... If I say:
ClassA a1, a2;
ClassB b;
a1.data = 5;
b = a1;
a2 = b;
then a2 should be identical to a1 and b should be 6.
First off I can't get this to compile because ClassB isn't know ClassA
at compile time...
Is it necesary to have int data in both classes or can A inherit from B
and vise versa?
Can both the casting operators exist in only on of the classes?
I guess this is very similar to:
float a1, a2;
int b;
a1 = 5.0
b = a1;
a2 = b;
Of course there is a loss of percision in this case.. but the casting
operations work...
help?
TIA
class ClassA {
public:
int data;
operator ClassB()
{
ClassB b;
b.data = data + 1;
return (b);
}
};
class ClassB {
public:
int data;
operator ClassA()
{
ClassB b;
b.data = data - 1;
return(b);
}
}
So... If I say:
ClassA a1, a2;
ClassB b;
a1.data = 5;
b = a1;
a2 = b;
then a2 should be identical to a1 and b should be 6.
First off I can't get this to compile because ClassB isn't know ClassA
at compile time...
Is it necesary to have int data in both classes or can A inherit from B
and vise versa?
Can both the casting operators exist in only on of the classes?
I guess this is very similar to:
float a1, a2;
int b;
a1 = 5.0
b = a1;
a2 = b;
Of course there is a loss of percision in this case.. but the casting
operations work...
help?
TIA