0

I have a very simple matrix class with the following constructor:

template <typename Type>
SimpleMatrix<Type>::SimpleMatrix(const int &rows, const int &cols, const Type &val) {
    for (int i = 0; i < rows; i++) {
        vector<Type> col_vec(cols, val);
        mat.push_back(col_vec);
    }
}

Simple as it is, if I try to call it from main.cpp by doing the following:

SimpleMatrix<double> matrix(1,1,0.5);

The compiler throws the well-known error:

Undefined symbols for architecture x86_64:
  "Matrix::SimpleMatrix<double>::SimpleMatrix(int const&, int const&, double const&)", referenced from:
      _main in main.o
  "Matrix::SimpleMatrix<double>::~SimpleMatrix()", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Isn't that the way of using overloaded constructors in this case? I am starting to think this is a red herring and my XCode is playing up!

Adam
  • 199
  • 11
  • You aren't a victim of [Why can templates only be implemented in the header file?](http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file), are you? – πάντα ῥεῖ Feb 12 '17 at 13:38
  • @πάνταῥεῖ indeed I was... thanks for the quick reply! – Adam Feb 12 '17 at 14:04

0 Answers0