4

I want a class to create a using alias from the return type of one of its base class' protected member functions. However, the following fails:

#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

Why doesn't D have access to the protected method of its base?

quant
  • 19,524
  • 28
  • 103
  • 199

0 Answers0