使用模板类

时间:2017-12-23 01:45:19

标签: c++ c++11 templates constructor

我正在编写模板类Foo,如下所示

foo.h中

template <class T>
class Foo{
public:
    Foo(int m, int n, T x);
private:
    int _m;
    int _n;
    T _x
};

Foo.cpp中

template <class T>
Foo<T>::Foo(int m, int n, T x):_m(m), _n(n), _x(x){}

现在,当我尝试初始化类时,我收到编译错误

int main()
{
    Foo<int> a (2,3, 4);
}

错误:

无效的参数'

未定义对`Foo :: ~Foo()'

的引用

对'Foo :: Foo(int,int,int)'

的未定义引用

.h或.cpp文件中是否有错误?或者我应该以不同的方式初始化课程?

0 个答案:

没有答案