C++ access privileges - Define access privileges in C++.

Define access privileges in C++.

You have access privileges in C++ such as public, protected and private that helps in encapsulation of data at various level.

Private :
If data are declared as private in a class then it is accessible by the member functions of the class where they are declared. The private member functions can be accessed only by the members of the class. By default, any member of the class is considered as private by the C++ compiler, if no specifier is declared for the member.

Public :
The member functions with public access specifier can be accessed outside of the class. This kind of members is accessed by creating instance of the class.

Protected :
Protected members are accessible by the class itself and it's sub-classes. The members with protected specifier act exactly like private as long as they are referenced within the class or from the instance of the class. This specifier specially used when you need to use inheritance facility of C++. The protected members become private of a child class in case of private inheritance, public in case of public inheritance, and stay protected in case of protected inheritance.
C++ Structures and Classes - Explain the difference between structures and classes.
C++ Structures and Classes - Syntactically and functionally, both structures and classes are identical. By default, members of structures..
C++ Container class - Explain container class and its types in C++.
C++ Container class - A container stores many entities and provide sequential or direct access to them. List, vector and strings are such containers...
C++ Storage Classes - Define storage classes in C++.
C++ Storage classes - Storage class defined for a variable determines the accessibility and longevity of the variable. The accessibility of the variable.
Post your comment