This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: class hirachy problem
- From: John Love-Jensen <eljay at adobe dot com>
- To: Kristian Kratzenstein <kristian dot kratzenstein at kielnet dot net>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Mon, 05 Dec 2005 10:42:28 -0600
- Subject: 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;
}