简体   繁体   English

部分模板类中不允许使用指向不完整类类型的指针

[英]pointer to incomplete class type is not allowed in a partial template class

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: 我在头文件中有一个模板类Param和一个局部专用模板类,用于参数,如下所示:

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 在模板类的专业化中,我在第65行收到此错误消息:“不允许不完整类型的Parameters.h”在第54行和第60行“指向不完全类类型的指针Parameters.h”

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. 这两个类都在同一个.h文件中。 Only the relevant code is copied here. 仅将相关代码复制到此处。 Thanks for your help. 谢谢你的帮助。

You probably forgot to include a header file with definition of a parameter class somewhere. 您可能忘记了在某个地方包含带有参数类定义的头文件。 This is the most common cause of the error. 这是错误的最常见原因。

Forward declaration works when you do not use fields from the declared class. 当您不使用声明的类中的字段时,前向声明有效。 Once you start using fields, you need a definition of this class. 一旦开始使用字段,就需要此类的定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “不允许指向不完整 class 类型的指针” - "Pointer to incomplete class type is not allowed" 指向不完整 class 类型的指针是不允许的 - Pointer to incomplete class type is not allowed 类中不允许使用不完整类型,但允许在类模板中使用 - Incomplete type is not allowed in a class, but is allowed in a class template 错误:不允许指向不完整类类型的指针 - error: pointer to incomplete class type is not allowed 具有类类型向量的前向声明-不允许指向不完整类类型的指针 - forward declaration with vector of class type - pointer to incomplete class type not allowed 错误:不允许指向不完整类类型的指针。 SDL / c ++ - Error: Pointer to incomplete class type is not allowed. SDL/c++ AActor * UactorComponent :: GetOwner const - 不允许指向不完整类类型的指针 - AActor *UactorComponent::GetOwner const - pointer to incomplete class type is not allowed 如何修复虚幻引擎 4 中的“不允许指向不完整类类型的指针”错误 - How to fix "Pointer to Incomplete class type is not allowed" error in Unreal Engine 4 不允许指向不完整的类类型“SDL_SysWMmsg”的指针 - Pointer to incomplete class type “SDL_SysWMmsg” is not allowed c ++ template使用模板内类的指针的不完整类型 - c++ template Incomplete type using pointer of class inside template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM