C + + Learning essay (basic concept article)

Source: Internet
Author: User

(i) base classes and derived classes

  • Derivation: Constructs a method of another class from one class so that the newly constructed class replaces the original class. For example, dogs derive automatic objects, and animal classes are the base classes of dogs. Derived classes include all members of the base class, in addition to their own members. In some contexts, a derived class is called a subclass , and a base class is called a parent class .
  • virtual function: A function defined in a base class that has a function of the same type and name in a derived class, and when the program calls the base class function, it actually calls a function of the derived class. This is often referred to as run-time polymorphism, dynamic dispatch, or run-time dispatch , because the specific invocation of which function is determined by the type of object the runtime actually uses.
  • virtual function table/virtual pointer: In order to handle a virtual function call (as described above), we need (and must) store more information in the base class or in a derived class, with the purpose of using these stored information to tell which function to call when we call virtual functions. This storage information, which we call VTBL (virtual function list, is actually the address of a function list), its address we use VTPR (virtual pointer) to represent
  • Overwrite: Defines a function of the same type as the virtual function in the base class, so that the function of the derived class is placed in the VTBL in place of the version in the base class
  • Pure virtual function: one or more virtual functions that must be overridden in a derived class. The goal of classes with pure virtual functions is to provide pure interfaces, meaning that they tend to not contain any data members, so there are no constructors
  • Private and protected members: we keep the implementation details of the class private to protect him from direct access, simplifying maintenance operations, which is called encapsulation .

inheritance, runtime polymorphism, and encapsulation use are, in fact, the most common flags of object-oriented programming.

Friend: Not studying yet

C + + Learning essay (basic concept 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.