Wednesday, September 17, 2008

Access Specifiers in C++

With C++, you can specify the level of access to member data and functions. There are three levels of access: public, protected, and private.

Access Specifiers:


Public : Available to everyone

Private : Class members declared as private can be used only by member functions and friends (classes or functions) of the class.
If someone tries to access a private member, they’ll get a compile-time error.

Protected : Class members declared as protected can be used by member functions and friends (classes or functions) of the class. Additionally, they can be used by classes derived from the class.

No comments: