Data encapsulation

Package is a concept of object-oriented programming operation data and the function data bound together, so to avoid outside interference and misuse, thereby ensuring safety. Data encapsulation come out another important OOP concepts, i.e., data hiding .

Data encapsulation is a mechanism to function data and operation data bundled together, data abstraction is an interface to a user and is exposed only to hide the implementation details of the mechanism.

 

Design Strategy

Under normal circumstances, we will set the class member state to private (private), unless we really need to be exposed, so as to ensure good encapsulation .

This usually applies to data members, but it also applies to all members, including virtual functions.

 

 

(Reprint)

 

In C ++ virtual functions may be private, and may be overridden by a subclass (since the transfer virtual function table), but can not call a private virtual subclasses of the parent class. Overloaded virtual function and authority of its statement has nothing to do.

A member function is defined as private property, which can only be marking the other members of the current class functions (or friend function) visit. The virtual modifier emphasizes the parent class member functions can be overridden in a subclass,

Because any call relationship with a parent class did not happen when rewriting, the rewrite is therefore allowed.

The compiler does not check the properties of various types of virtual functions. The modified virtual member functions, whether they are private, protect or public, will be placed into a unified virtual function tables. Parent classes is derived

, Subclass inherits the vtable has the same offset address (offset address refers to the same, offset with respect to each of the virtual function pointer VPTR), the subclass will be allowed to reload these virtual functions.

It can give new property when overloaded function definitions and overloaded, such as public, it only marks the overloaded function access properties in the subclass for the public, and private property of the parent class has nothing to do!

Pure virtual function can be designed to be private, but this does not allow non-friend function outside of this class call it directly, only the obligations of this subclass pure virtual function coverage, it was not the right call.

Guess you like

Origin www.cnblogs.com/webcyh/p/11293827.html