派生类在实例化期间无法访问受保护的成员

时间:2014-10-03 06:23:21

标签: c++

我希望一个类从其基类“using成员函数之一的返回类型创建protected别名。但是,以下失败:

#include <type_traits>
class B
{
protected:
    int fun(){return 0;}
};

class D : protected B
{
    using T = decltype(std::declval<B>().fun());
};

main() {}
prog.cpp:5:6: error: ‘int B::fun()’ is protected
  int fun(){return 0;}

Live example

为什么D无法访问其基础的受保护方法?

0 个答案:

没有答案
相关问题