0

What is the right way to access a parent's protected variable?


template<typename T>
struct A
{
    A() : i(2) {}
protected:
    int i;
};
template<typename T>
struct B : public A
{
    void foo() { std::cout << A<T>::i << std::endl; }
};

This will correctly print out 2.

Is there another way to do it with inheritance?

Should I instead of inheritance make B a friend?

user644361
  • 272
  • 1
  • 5
  • 15

0 Answers0