Name: Anonymous 2006-01-19 14:12
I've got this problem and I'm not sure how to solve it. I have:
class A {
public:
A() {};
~A{} {};
void saveToXML(FILE *out);
void loadFromXML(xmlNodePtr node);
};
Derived from A, I have several classes that do not reimplement savToXML() because all the member data is the same. The only reason I have derived classes in the first place is to reimplement various member functions.
Obivously, when I'm ready to read the data back in from a file I do something similar to the following:
A *in = new A();
in->loadFromXML(node);
Of course, this results in me losing my polymorphism after the data structure has been saved and read back in.
So the question is this. Is there any way to identify exactly what class saved the data in the first place and downcast a pointer to that type when reading the data back in without having to overload loadFromXML() in every derived class? We're talking about hundreds of derived classes here, so I really don't want to do that.
Thanks!
class A {
public:
A() {};
~A{} {};
void saveToXML(FILE *out);
void loadFromXML(xmlNodePtr node);
};
Derived from A, I have several classes that do not reimplement savToXML() because all the member data is the same. The only reason I have derived classes in the first place is to reimplement various member functions.
Obivously, when I'm ready to read the data back in from a file I do something similar to the following:
A *in = new A();
in->loadFromXML(node);
Of course, this results in me losing my polymorphism after the data structure has been saved and read back in.
So the question is this. Is there any way to identify exactly what class saved the data in the first place and downcast a pointer to that type when reading the data back in without having to overload loadFromXML() in every derived class? We're talking about hundreds of derived classes here, so I really don't want to do that.
Thanks!