Why can't I access a protected member from an instance of a derived class?

后端 未结 8 1142
难免孤独
难免孤独 2020-12-01 16:46

I haven\'t done C++ in a while and can\'t figure out why following doesn\'t work:

class A {
protected:
  int num;
};

class B : public A {
};

main () {
  B          


        
8条回答
  •  隐瞒了意图╮
    2020-12-01 17:13

    You are seeing exactly what's expected. Try this - http://www.learncpp.com/cpp-tutorial/115-inheritance-and-access-specifiers/ for info on inheritance access specifiers.

提交回复
热议问题