更新时间:2023-02-15 15:02:22
是受保护的成员可以通过派生类访问,但是您正在main()函数中访问它,这是在层次结构之外。如果你在类B中声明一个方法并访问num,它会很好。
yes protected members are accessible by derived classes but you are accessing it in the main() function, which is outside the hierarchy. If you declare a method in the class B and access num it will be fine.