I've created a class that's designed to rotate a vector. (I realize this functionality basically already exists in STL, I'm just trying get a handle on template classes.)
My specification file:
template <class T>
class ShiftVec {
private:
vector<T> vec;
public:
ShiftVec(vector<T>);
vector<T> getVec();
void shiftRight(int);
void shiftLeft(int);
};
My implementation file:
template <class T>
ShiftVec<T>::ShiftVec(vector<T> v) {
vec = v;
}
template <class T>
vector<T> ShiftVec<T>::getVec() {
return vec;
}
template <class T>
void ShiftVec<T>::shiftRight(int n) {
rotate(vec.begin(),
vec.end()-n, // this will be the new first element
template class ShiftVec<int>;
template class ShiftVec<double>;
template class ShiftVec<bool>;
template class ShiftVec<string>;
When I run this, I get a bunch of errors that look like this:
Undefined symbols for architecture x86_64:
"ShiftVec<int>::shiftRight(int)", referenced from:
_main in main.o
"ShiftVec<int>::getVec()", referenced from:
_main in main.o
"ShiftVec<int>::ShiftVec(std::__1::vector<int, std::__1::allocator<int> >)", 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)
I'm not sure exactly what's going wrong here. A push in the right direction would be helpful.