I am modifying some existing code in a project. I have a template class Param and a partial specialized template class for parameters in a header file as below:
template<class ValueType>
struct Param
{
static void add(ParameterCode code, ValueType value, ParameterAttributes attributes)
{
}
static PreSetResultType preSetActions(ParameterCode code, ValueType& value)
{
return (SUCCESS);
}
static void set(ParameterCode code, ValueType value)
{
}
static ValueType get(ParameterCode code)
{
ValueType value = ValueType();
return (value);
}
static void serialize(ParameterCode code, vector<uint8_t>& byteArray)
{
}
static ValueType deserialize(const vector<uint8_t>& byteArray)
{
return (*reinterpret_cast<const ValueType*>(byteArray.begin()));
}
};
/* template function specialization for pointer types */
template<class ValueType>
struct Param<ValueType*>
{
static void add(ParameterCode code, ValueType* value, ParameterAttributes attributes)
{
}
static PreSetResultType preSetActions(ParameterCode code, ValueType*& config)
{
return (SUCCESS);
}
static void set(ParameterCode code, ValueType* pObjNew)
{
pObjNew->serialize(serializedObject); //error line 54
}
static ValueType* get(ParameterCode code)
{
void* value = NULL;
return ((ValueType*)value);
}
static void serialize(ParameterCode code, vector<uint8_t>& byteArray)
{
ValueType* obj = get(code);
obj->serialize(byteArray); //error line 60
}
static ValueType* deserialize(const vector<uint8_t>& byteArray)
{
return (ValueType::deserialize(byteArray)); //error line 65
}
};
in the specialization of template class I get this error message: "incomplete type is not allowed Parameters.h" at line:65 "pointer to incomplete class type is not allowed Parameters.h" at line:54 and 60
I know that the specialization of template class has at incomplete type but the compiler should resolve it at compile time, or do I need some sort of forward-declaration. Both the classes are in same .h file. Only the relevant code is copied here. Thanks for your help.