   dynamic_cast with templates
  I have this: two classes, one of them derives from the other and is also a template. Then I use dynamic_cast to cast the base to a derived template. Very rough code:class Base{}template<class T>class Derived : Base{}Base* b;Derived<T>* casted = dynamic_cast<Derived<T>*> (b);casted is always NULL! why? Base IS polymorphic, it has virtual functions implemented by Derived...   
  Just in case, in the actual code you have:class Derived : public Base{right?If that's not it, post the actual code.   ;  Are you missing a virtual destructor in the base class ? Otherwise I can see no other reason why this should fail.   ;  Post full test case?  This code works fine on my system#include<iostream>#include<typeinfo>using namespace std;class Base{public:void print(){cout << "From Base" << endl;}virtual ~Base() {}};template<class T>class Derived: public Base{public:void print(){cout << "From Derived, with [T="<< typeid(T).name() << "]" << endl; }};int main(int argc,char** argv){Derived<int> Di;Derived<int> *Dip;Derived<bool> Db;Derived<bool> *Dbp;Base* b=&Di;b->print();Dip=dynamic_cast<Derived<int>* >(b);Dip->print();b=&Db;b->print();Dbp=dynamic_cast<Derived<bool>* >(b);Dbp->print();return 0;};Output:From BaseFrom Derived, with [T=i]From BaseFrom Derived, with [T=b];  In above code - b is undefined, and b is of type Base, so it can never be legally cast to Derived.   ;  full code:class CProperty{  public:  CProperty(){};  virtual void activate() = 0;  virtual ~CProperty(){};   };template<class T>   class CMaterialProperty : CProperty{  public: CMaterialProperty(CMaterial* material,std::string n):CProperty(), _material(material),_name(n){}; virtual ~CMaterialProperty(){}; void setActivationCallback(void (*callback)(const T&)){_activateCallback = callback; } void activate(){(*_activateCallback)(_value); }; void setValue(const T& value){_value = value; }; CMaterial* getMaterial(){return _material;} std::string getName(){return _name;}  protected: CMaterial* _material; T _value; std::string _name; void (*_activateCallback)(const T&);  friend class CMaterial;   };template<class T> CMaterial::CMaterialProperty<T>* getProperty(std::string name){  CMaterial::CMaterialProperty<T>* casted = dynamic_cast<CMaterial::CMaterialProperty<T>*> (_properties[name]);  if (casted == NULL){ std::cout<<"OMG!";  }  return casted;}//IN SOME OTHER PLACE....CMaterial::CProperty* p = new CMaterial::CMaterialProperty<CVector4>(material,"Color");material->getProperty<maths::CVector4>("Color")->setValue(CVector4(1,0,0,1));all of that is defined inside a "CMaterial" class, hence the getProperty method qualifier.   ;  I see you ignored my reply. [smile]   ;Quote:Original post by Gage64I see you ignored my reply. [smile]omg! my brain skipped the "public" keyword both in my code and in your reply :D. thank you very much for the help and the quick responses!   