#include <assert.h> #include <typeinfo> struct CTreeObject1 { }; /************************************************************************/ /* Nammed structs - for using one type more than once in SinglesCont. */ /************************************************************************/ template< class TObject, class TName> struct NammedObject : public TObject, public TName { typedef TObject object_type; }; struct stFirst{}; struct stSecond{}; template <typename T> struct UnpackObjectType { typedef T TT; }; template<typename T, typename U> struct UnpackObjectType< NammedObject<T, U> > { typedef T TT; }; int main() { typedef NammedObject<CTreeObject1,stFirst> T1; typedef NammedObject<CTreeObject1,stSecond> T2; typedef CTreeObject1 T3; UnpackObjectType<T1>::TT d1; UnpackObjectType<T2>::TT d2; UnpackObjectType<T3>::TT d3; //required assert( typeid(d1) == typeid(d2)); assert( typeid(d2) == typeid(d3)); return 0; }
Tag: templates
g++ error: expected primary-expression before > token
For g++ compiler is sometimes necessary to specify more typename / template keywords than for Visual Studio. This is one of examples.
To the following code it’s necessary to add template keyword:
TMemoryManager & memMngr = GetMemoryManager(); m_pObject = memMngr.CreateObject<TObject>(this, m_pContainerOwner);
use
TMemoryManager & memMngr = GetMemoryManager(); m_pObject = memMngr.template CreateObject<TObject>(this, m_pContainerOwner);