Protected members are accessible from the derived classes. #include <iostream> class B { protected: const int a = 3; }; class D : B { public: void foo() { std::cout << a << std::endl; } }; int main() { D d; d.foo(); } Output: 3. The protected member (a) of the base class (B) is accessible from the derived class (D).
2019 Feb 4, 8:48:20 AM
The question is a bit misleading IMO. Does this case falls under the problem's condition? class A { protected: const int a = 3; }; class B : A { void foo() { std::cout << a << std::endl; };
2019 Jan 11, 4:52:53 PM
Войдите чтобы поставить Нравится
Войдите чтобы прокомментировать