模板多重继承歧义符号错误

Template multiple inheritance ambigious symbol error

我遇到了一个真正的问题,可以总结如下:

template <typename BaseType>
class TemplateClass
{
public:
    template <typename BaseTypee, unsigned PrefixID>
    static void deleteType(unsigned int ObjID)
    {

    }
};

class ParentClass:
    public TemplateClass<ParentClass>
{
};

class ChildClass:
      public ParentClass, public TemplateClass<ChildClass>
{   
    using TemplateClass<ChildClass>::deleteType; //Ambigious Symbol Compiler-Error

};

我这样调用函数 deleteType

TemplateClass<ChildClass>::deleteType<ChildClass, ChildType>(ChildType);

我想在 ChildClass Class 中调用函数 deleteType,但没有任何声明该函数将在 ParentClass.

中调用

如何消除使用短语中的模糊符号错误?可以用不同的方法完成我的任务吗?

仅供参考:最初,我尝试调用该函数(没有任何变化)

ChildClass::deleteType<ChildClass, ChildType>(ChildType);

有趣的是:尽管有红色下划线,它仍然可以编译。如果我调试,模板仍将在 ParentClass 中调用,在编译时既不会发出警告也不会引发错误..

将您的 using 声明放在 public: 部分:

template <typename BaseType>
class TemplateClass
{
public:
    template <typename BaseTypee, unsigned PrefixID>
    static void deleteType(unsigned int ObjID)
    {
    }
};

class ParentClass:
    public TemplateClass<ParentClass>
{
};

class ChildClass:
      public ParentClass, public TemplateClass<ChildClass>
{   
public:
    using TemplateClass<ChildClass>::deleteType;
};

int main() {
    ChildClass::deleteType<void, 0>(0);
}