Protected Data Elements and Data Functions

when I declare a protected data item in a class, which means that it is not available to the outside world, but to a derived class. My question is:

will it be available for a class derived from a derived class?

+4
source share
3 answers

Yes, protected data members are available right up to the inheritance hierarchy.

Protected data is usually best avoided. An alternative is to create secure methods for accessing personal data. This allows you to store data in one class. It also makes it easy to set a breakpoint for data changes.

+6
source

In fact, a protected data member is only accessible using secure and open inheritance.

Here is an example where a protected member is not available in a derived class:

class Base { protected: int iBase; }; class Derived : private Base { // iBase not accessible }; 
+3
source

Yes. (By the way, you would just try this.)

+2
source

Source: https://habr.com/ru/post/1332159/


All Articles