I have the following situation(simplified from my actual problem):
// In Tree.hpp
template <class T>
class Tree : public Plant {
...
// Returns true if valid for purposes
bool valid() const override;
}
The template parameter can be either a Deciduous or Coniferous, or a child of those types such as Pine or Oak.
I would like to differentiate valid() based on whether the templated parameter is Deciduous or a child, or Coniferous or a child, meaning two versions.
// In Tree.cpp
template<>
bool Tree<Coniferous>::valid() const {
//Coniferous valid logic
}
template<>
bool Tree<Deciduous>::valid() const {
//Deciduous valid logic
}
This does not work, as I get errors such as:
libForest.so: undefined reference to `Tree<Pine>::valid() const'
libForest.so: undefined reference to `Tree<Oak>::valid() const'
What is the correct way to do this?