dimanche 28 août 2016

Linker Error when create function template for iterator [duplicate]

This question already has an answer here:

I ran into this problem:

EuclideanVector.h

class EuclideanVector {
private:
    // some stuff
public:
    template<typename T>
    EuclideanVector(T a, T b);
    // EuclideanVector(const T& a, const T& b);
    // Some other stuff
}

EuclideanVectorTester.cpp

int main() {
    std::list<double> l {1,2,3};
    evec::EuclideanVector g{l.begin(),l.end()};
}

and I get:

Undefined symbols for architecture x86_64:
  "evec::EuclideanVector::EuclideanVector<std::__1::__list_iterator<double, void*> >(std::__1::__list_iterator
<double, void*>, std::__1::__list_iterator<double, void*>)", referenced from:
      _main in EuclideanVectorTester.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [EuclideanVectorTester] Error 1

Does anyone have any idea why? Ultimately, I want to create a template for iterator (either from std::vector or std::list).

Much appreciated

Thang

Aucun commentaire:

Enregistrer un commentaire