What you usually did in this case is to give B constructor that takes A :
class B { public: B(const A&); };
And do the conversion there. The compiler will say: "How can I make A a B ? Oh, I see that B can be built from A "
Another method is to use the conversion operator:
class A { public: operator B(void) const; }
And the compiler will say: "How can I do A a B ? Oh, I see that A can be converted to B "
Keep in mind that it is very easy to abuse. Make sure that it really makes sense for the two types to implicitly transform each other.
GManNickG
source share