including a class template within a map
I have a template class Test, and I am trying to define the following function in a separate header file:
template<typename T>
T dtest(const int, std::map<int, Test<T> >& y);
but I get the following error:
‘Test’ was not declared in this scope
template argument 2 is invalid
开发者_Python百科template argument 4 is invalid
Given that you assert that the header that defines Test<T>
is included by the header that declares dtest
, I'm going to guess you have a circular include: The Test<T>
header also includes the dtest
header.
#include <map>
template<class T>
class Test{};
template<typename T>
T dtest(const int, std::map<int, Test<T> >& y);
This compiles fine so as long as you include the definition of Test and map; the code is fine.
精彩评论