This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: class hirachy problem


Hi Kristian,

Works for me (see below).

Note:  the virtual destructor is vitally important, since you are using
inheritance, parent pointers, and dynamic_casts.

--Eljay

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#include <iostream>
using std::cout;
using std::endl;

class CAlpha
{
public:
  virtual ~CAlpha() { }
};

template <typename T_Any>
class CBeta : public CAlpha
{
  T_Any* any;
public:
  CBeta() : any(new T_Any) { }
  virtual ~CBeta() { }
};

class CGamma
{
};

int main()
{
  CAlpha* a = new CBeta<CGamma>;
  CBeta<CGamma>* bg = dynamic_cast<CBeta<CGamma>* >(a);
  cout << (void*)bg << endl;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]