I've been wondering about this for a while, stackoverflow had a bunch of related, but not quite the same questions, so I'm asking it here.
Is it possible for a templated class to have methods in the cpp that do not depend on this template? Evidently these methods aren't affected by the template, so the compiler should be able to compile them separately.
If not possible, what would be a workaround, if I really, really want to separate this code?
template<typename T>
class MyAwesomeVectorClone{
size_t size;
size_t capacity;
T* data;
bool doesSizeExceedCapacity(); // non template method, define in cpp?
void add(T& t){// template method
}
}
bool MyAwesomeVectorClone::doesSizeExceedCapacity() {
return size > capacity;
}
compiled separately, but yes you can place them in the source file although you still need the template parameter in the function signature:template <class T> bool MyAwesomeVectorClone<T>::doesSizeExceedCapacity() { return size > capacity; }