Pretty new to working with templates in C++. I want to create a template specialization of a class function depending on whether a single object pointer is passed to the function, or a std::vector of object pointers. I want the std::vector to be passed by reference. I can't quite figure out the required syntax:
StateEvolver.h
#ifndef STATEEVOLVER_H
#define STATEEVOLVER_H
#include "Vehicle.hh"
class stateevolver
{
public:
stateevolver();
template<typename T> void evolveState(T, double time);
};
// Template specialization declarations for functions using either std::vector<vehicle*> or single vehicle pointer
template<>
void stateevolver::evolveState<std::vector<vehicle*>&>(std::vector<vehicle*> & , double time);
template<>
void stateevolver::evolveState<vehicle*>(vehicle*, double time);
#endif
StateEvolver.cpp
template<>
void stateevolver::evolveState<std::vector<vehicle*>&>(std::vector<vehicle*> & vehicleVec, double time) {
}
I instantiate this in another file like so:
MyStateEvolver.evolveState(vectorOfVehiclePointers, time); // COMPILE ERROR
and receive this compile time error:
undefined reference to `void stateevolver::evolveState<std::vector<vehicle*, std::allocator<vehicle*> > >(std::vector<vehicle*, std::allocator<vehicle*> >, double)'
Any ideas where I'm going wrong? Thanks.