Access Control

C++ has a third access specifiers or visibility mode called protected. This access specifiers protected plays an important role in inheritance. A member declared as protected is accessible by member function in its class or any class derived from its own class objects can never access private and protected member of a class directly. On the other hand, objects can reach these members through the public member functions in the class.
            There are three kinds of functions accessing a class: functions implementing the class (its friends and members), functions implementing a derived class (the friends of derived class and members) and other functions. A member of a class can be private, protected or public.
If a member is private, only member functions and friends of the class in which it is declared can use its name.
If it is protected only member functions and friends of the class in which it is declares and by member functions and friends of classes derived from this class can be use its name.
If a member is public, its name can be used by any function.

Access specifiers
Member functions and friends
Derived class member functions and friends
General users
Public
Yes
Yes
Yes
Protected
Yes
Yes
No
Private
Yes
No
No
Posted by Unknown On 00:14 No comments

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *