C ++ primer (10)-Object-Oriented Programming

Source: Internet
Author: User

A base class usually defines any function that needs to be redefined as a virtual function. Virtual only appears in the member function declaration within the class, and cannot appear outside the class definition body. Virtual is used to start dynamic binding.

Generally, virtual destructor must be defined for the root class at the inheritance level.

A derived class generally redefines the inherited virtual function. If the derived class does not redefine a virtual function, use the version defined in the base class. When a derived class redefinition of a virtual function, you can use virtual reserved words, but not required.

A derived class object consists of multiple parts: A member defined by the derived class and a sub-object composed of base class members. The class can access the public protected members of its base class, it is as if the members are members of the derived class.

Inherited type
Public: The base class members maintain their own access level. The Public Member of the base class is the Public Member of the derived class, and the protected member of the base class is the protected member of the derived class.
Protected: the public and protected members of the base class are all protected members in the derived class.
PRIVATE: all the members of the base class are private members in the derived class.

By default, the inherited class is private, and the inherited struct is public by default.

Classes that contain one or more pure virtual functions are abstract base classes. Apart from being a part of an object of A derived class of the abstract base class, you cannot create abstract objects.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.