Is it possible to have templated classes in a templating class?
template <class M, class A> class C { std::list<M> m_List; ... }
Is the above code possible? I would like to be able to do something like this.
Why am I asking that I am getting the following error:
Error 1 error C2079: 'std::_List_nod<_Ty,_Alloc>::_Node::_Myval' uses undefined class 'M' C:\Program Files\Microsoft Visual Studio 9.0\VC\include\list 41
+1
source to share
4 answers
My guess: you posted your declared M class somewhere and only declared it in full after you create the template.
My hint: give your formal template arguments a different name than the actual one. (i.e. class M)
// template definition file
#include <list>
template< class aM, class aT >
class C {
std::list<M> m_List;
...
};
An example of an unsuccessful declaration leading to the specified error:
// bad template usage file causing the aforementioned error
class M;
...
C<M,OtherClass> c; // this would result in your error
class M { double data; };
An example of a correct declaration that does not result in an error:
// better template usage file
class M { double data; }; // or #include the class header
...
C<M,OtherClass> c; // this would have to compile
+4
source to share