I'm having a problem with a Template specialization since I don't want to redefine a method, I want to use the generic one.
template<class VarsContainer, class Specific>
class State
{
public:
State();
~State(){}
HSError_t Update(LoggerData const &lData);
VarsContainer state;
void swap(State &rhs);
State & operator=(State rhs); // pass by value copy
protected:
void UpdateSpecific(Specific *rhs);
Specific specificPtr;
};
And in the implementation I do the following:
template<class VarsContainer, class Specific>
HSError_t State<VarsContainer, Specific>::Update(LoggerData const &lData)
{
HSError_t error_t = HeatInterfaceError;
specificPtr = const_cast<Specific>(&lData);
error_t = UpdateSpecific(specificPtr);
if(error_t != HeatSuccess)
{
return error_t;
}
return error_t;
}
template<class VarsContainer, class Specific>
HSError_t State<VarsContainer, Specific>::UpdateSpecific(Specific *rhs)
{
HSError_t error_t = HeatInterfaceError;
return error_t;
}
After doing that I specialize the template in the following manner:
template<>
class State<ChemicalVars, Chemicals*>
{
public:
ChemicalVars state;
protected:
HSError_t UpdateSpecific(Chemicals *chemicals);
Chemicals *specificPtr;
};
And I define UpdateSpecific in a cpp file copying data from the specialized struct to the local state.
Problem is that when I try to call the "Update" method the compiler does not created a definition for it in my specialized template of ChemicalVars.
Afterwards I change my specialization with:
template<>
class State<ChemicalVars, Chemicals*>
{
public:
ChemicalVars state;
HSError_t Update(LoggerData const &lData);
protected:
HSError_t UpdateSpecific(Chemicals *chemicals);
Chemicals *specificPtr;
};
But still, the error is the same:
undefined reference to `State<ChemicalVars, Chemicals*>::Update(LoggerData const&)'
Problem is the generic implementation is good, I just want to use the one defined in the Generic State to be used by the specializations.