我正在尝试创建一个简单的模板类,其中我创建了一个模板类的对象,提供了一个容器作为模板类型,根据我对模板的理解,这应该没有问题,应该像int或char一样处理,但它总是给我一个错误,说:
"template argument 1 is invalid"下面是我遇到这个错误的那一行:
templateTest<(std::list<int>)> testingTheTemplate;下面是template类的框架
template <class testType> class templateTest
{
/* use some iterators and print test data here */
};这里我漏掉了什么?
发布于 2011-12-22 16:21:08
您忘记了类定义后的分号:
template <class testType> class templateTest
{
}; // <- semicolon另外,将您的实例化声明为:
templateTest<std::list<int> > testingTheTemplate;
// ^^^ required space (C++03)没有括号,注意中间的空格。
在C++11之前,<<和>>被视为运算符。在这种情况下,您必须将它们分开。
发布于 2011-12-22 16:21:09
它应该是
C++03中的templateTest<std::list<int> > testingTheTemplate;
或C++11中的templateTest<std::list<int>> testingTheTemplate;
https://stackoverflow.com/questions/8601060
复制相似问题