> This does not compiler neither. The _static_ type of 'x' is X* and
this cannot be converted implicitly to AX* or BX*. The _dynamic_ (or
runtime) type of 'x' is 'CX', but the compiler does not know that, the
runtime system does. So the compiler is only trying to convert X* to
AX* or BX* and it simply cannot. That's the same thing as converting
a MyClass to a UnrelatedOtherClass.
Hm... couldn't I tell the compiler that this should be resolved
at runtime?
<snip/>
Something like that ?
class X
{
public:
void serialize();
virtual ~X();
// pure virtual, child must implement it
void deserialize() = 0;
};
<snip/>
That doesn't help because the information of which
object needs to be created comes from the stream.
So I need a factory that knows about
Classname = GUID
AX = 1
BX = 2
CX = 3
Whateverclass = 4
So it can create the appropriate object on runtime.
The GUID -> class is done in the factory. But for
not messing up with the ids I also should ask the
factory for class -> GUID.
Even if I register the classes to the factory
Factory::Register("AX",1);
Factory::Register("BX",2);
Factory::Register("CX",3);
I need to get the textual representation of
the object on serialization.
AX* a = new AX();
a -?-> "AX"
Only way I see up to now is having a virtual
"GetClassname()" function in each object
returning the classname.
--
Torsten