用于级联继承的 C++ 可变参数模板。如何向上转换?

C++ variadic templates to cascade inheritance. how to upcast?

给定 C++ 中的级联继承层次结构:

struct MyBaseClass
{
protected:
   void f();
};

template <typename Fn, typename... Args>
struct MyClass<Fn, Args...> : MyClass<Args...>
{
...//from here can I access MyBaseClass::f() ?
}; 
template <typename Fn>
struct MyClass<Fn> : MyBaseClass{...};

如上面注释行所示,我想从 MyClass 的范围内调用 MyBaseClass 的受保护方法。 这怎么可能?

I want to call a protected method from MyBaseClass from the scope of MyClass.

有几种方法可以从派生的 class:

调用基础 class 的 模板相关函数
this->f();         // Call f of this class, or any base class.
this->MyClass::f() // Call MyClass::f of MyClass base sub-object of this class only.
MyClass::f()       // Call MyClass::f either of MyClass base sub-object or of any unrelated MyClass.

有关详细信息,请参阅 Dependent names

Maxim 的另一种替代解决方案是使用 class 的名称 (demo) 完全限定函数名称:

MyBaseClass::f();