class T { // base class
public:
};
class TA : public T {
private:
double md_num;
public:
};
class TB : public T {
private:
bool mb_xx;
public:
};
void AnyFunction() {
TA Ta, Tb;
T *pT1, *pT2;
pT1 = &TA
// now we want to deep-copy pT1 to have it in pT2
pT2 = new ???actual typeinfo needed??? (*pT1); // I don't know what to write there
}
Real-time type information
Here is my problem:
What's the solution? Should I define some virtual new that investigate the exact type and then utilizes the appropriate copy constructor or what?
If I had something like GetRunTimeType(instance) "function" with type returned, I would be saved but I haven't find any usable keyword in my MSDN. Please, help me!
[edited by - xropi on October 17, 2002 9:22:17 AM]
quote:Original post by SabreMan
Use the "virtual constructor" or "clone" idiom. See: The C++ FAQ Lite for details.
I use MS VC6.0 which doesn't support "covariant return types" used with virtual Clone() so I have to return a pointer to my base class. Not so nice, but it works. Thank you.
[edited by - xropi on October 17, 2002 10:44:24 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement