C++ VS2019 c++;深层继承模板中的C3861错误

C++ VS2019 c++;深层继承模板中的C3861错误,c++,c++17,visual-studio-2019,C++,C++17,Visual Studio 2019,VS2019中的/permissive-compiles出现C3861错误,因为我有一个深层继承层次结构,其中派生最多的模板从派生自类的根访问受保护的符号 class BaseClass { protected: void baseClassMethod() { m_value = 0; } int m_value; }; template<typename T1> class DerTmpl_1 : public BaseClas

VS2019中的/permissive-compiles出现C3861错误,因为我有一个深层继承层次结构,其中派生最多的模板从派生自类的根访问受保护的符号

class BaseClass
{
protected:
    void baseClassMethod()
    {
        m_value = 0;
    }

    int m_value;
};

template<typename T1>
class DerTmpl_1 : public BaseClass
{
public:
    T1 doTheThing(T1 t)
    {
        baseClassMethod();
        m_value = 123;
        return t;
    }
};

template<typename T1, typename T2>
class DerTmpl_2 : DerTmpl_1<T1>
{
public:
    T2 doTheOtherThing(T1 t1, T2 t2)
    {
        baseClassMethod();  // C3861 here, but only with /permissive-
        doTheThing(t1);     
        m_value = 456;      // C3861 here, but only with /permissive-
        return t2;
    }
};

您需要使用
来访问依赖于模板参数的基类的数据成员:

    this->baseClassMethod();  // C3861 here, but only with /permissive-
    doTheThing(t1);     
    this->m_value = 456;      // C3861 here, but only with /permissive-

请注意,该问题与深层继承层次结构无关,它可能仅在从类模板继承时发生。非依赖名称不会在依赖基类中查找,另一方面,在模板中使用的名称会推迟到模板参数已知为止

您需要为那些来自依赖基类(依赖于模板参数
T1
)的名称设置依赖项,例如


什么是错误“C3861”?请将完整的错误输出复制粘贴到问题正文中。
:public DerTmpl_1
我建议不要在发布时使用最新版本的Visual Studio。它们通常有缺陷,并且无论如何都不立即支持最新的标准。根据@SomeProgrammerDudeThank,使用C3861错误输出进行更新。您知道这是否只是间接继承类的一个要求吗?nvm,看起来上面列出了理由:来自@aschepler
    this->baseClassMethod();  // C3861 here, but only with /permissive-
    doTheThing(t1);     
    this->m_value = 456;      // C3861 here, but only with /permissive-
this->baseClassMethod();
this->m_value = 456;
BaseClass::baseClassMethod();
BaseClass::m_value = 456;