I would like to be able to initialize variables using other initialized variables. I am unable to workout how to formulate line 29. Any help will be gratefully received.
I'll use an example with different class names as your can be confusing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Overload constructor:
class B; // forward declaration
class A
{
// some members
A ( const B& ); // construct from B -forward declaration-
};
class B
{
// ...
};
A::A ( const B &b ) // constructor body after class B body so that it will know which are B's members
{
// convert here
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//Conversion operator
class A
{
// ...
};
class B
{
//...
operator A () // conversion operator
{
A tmp;
// modify 'tmp' as you wish so that it will be the converted value
return tmp;
}
};