的成员函数我是新来的C++和Im学习使用模板。 我想使模板类与2个模板参数,并且从类专门的单个成员函数,对于其中所述第二模板参数是模板上的指针类型的第一个参数的矢量的情况。我想的是我的尝试会更加清楚的例子:C++专门为载体
//Container.h:
template<class T , class CONT >
class Container {
private:
CONT container;
T someData;
public:
void foo();
};
,我尝试了特化了的std ::向量是:
//Container.cpp
template<class T>
void Container<T, std::vector<T*> > ::foo(){
cout << "specialized foo: " << container.pop_back();
}
template<class T, class CONT >
void Container<T, CONT > ::foo(){
cout << "regular foo: " << container.pop_back());
}
,但我得到这些erors:
error C3860: template argument list following class template name must list parameters in the order used in template parameter list
error C2976: 'Container<T,CONT>' : too few template argument
Container类的使用必须是该第一参数是某种类型的,并且第二个是一个STL容器,载体或列表。例如:
Container<int, vector<int*> > c;
c.foo();
我是什么东错了?
除了语法错误,你不能专注函数模板部分,所以这种方法不工作。 –