My Initial implementation approach in .cpp is like the following:
using namespace std;
...
template <typename T>
void print2dvector(vector<vector<T> > v) {
for(int i = 0; i < v.size(); i++) {
for(int j = 0; j < v[i].size(); j++) {
cout << v[i][j] << " ";
}
cout << endl;
}
}
The declaration in .h file is the following
template <typename T> void print2dvector(std::vector<std::vector<T> > v);
Here is how I use it,
print2dvector<int>(vec_of_vec);
The compile stage passes, but failed in linking stage. The error is the following:
Undefined symbols for architecture x86_64:
"void print2dvector<int>(std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >)", referenced from:
spiral_matrix_ii_Challenge::Execute() in spiral_matrix_ii.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please let me know if I miss anything conceptually in implementing this.