`

c++ information hiding and the access specifier

    博客分类:
  • c++
c++ 
阅读更多

I know this common sense but just want to have them somewhere so that we can refers to sometime when we need it.

 

Information hiding, as we called the "encapsulation" is one of the beauty of OO programming. Information hiding is a formal mechanism for preventing the functions of a programs to access directly the internal representation of class type. The access restriction is specified by the labeled public, private, and protected sections with the class body. The keywords public, private, and protected are called access specifiers. Members declared within a public section are public mmebers; those declared within a private or protected section are private or protected members.

 

public member

Public members are accessible from anywhere within a program. A class that enforces information hiding limits its public members to the member functions that define the operation that can be used by the general program to manipulate objects of that class type.

 

Private member 

Pirvate member can be accessed only by the member functions and friends of its class. A class that enforces infromation hiding declares its data members as private. 

 

protected member

Protected member behaves as a public mmeber to a derived class. and behave as a private member to the rest of hte program. 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics