Re: class hirachy problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux