Archived

This topic is now archived and is closed to further replies.

Real-time type information

This topic is 5540 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is my problem:
    

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

}
    
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites