I would like to be able to initialize a derived class from a base class, for example:
class X {
public:
X() : m(3) {}
int m;
};
class Y : public X {
public:
Y() {}
Y(const & X a) : X(a) {}
};
Is there anything dangerous or unusual doing this? I want this because I deserialize a bunch of objects that are of the type I don’t know right away, so I basically want to use X as a temporary storage while I read the entire serialized file and then create my objects Y (and W, X, Y objs, depending on the data) using this data afterwards. Maybe there is an easier way that I am missing.
Thanks!
Steve source
share