Hi, I'd like to be able to initialize a derived class from a base class, like so:
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 by doing that? I want it because I'm deserializing a bunch of objects who's type I don't immediately know, so I basically want to use X just as some temp storage while I'm reading the whole serialized file, and then create my Y objects (and W, X, Y objs, depending on the data) using that data afterwards. Maybe there's a easier way I'm missing.
Thanks!