vendredi 22 décembre 2017

C++ constructor initialization when using template classes [duplicate]

This question already has an answer here:

I am writing a template class Foo as follows

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){}

Now, when I try to initialize the class, I get a compilation errors

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

Errors:

Invalid arguments '

undefined reference to `Foo::~Foo()'

undefined reference to `Foo::Foo(int, int, int)'

Is there any mistakes in the .h or the .cpp files? or should I initialize the class in a different way?

Aucun commentaire:

Enregistrer un commentaire