Virtual functions and virtual inheritance

Source: Internet
Author: User

Base classes all of the derived classes that re-want it to each define a version that is appropriate for itself, at which point the base class declares these as virtual functions.

Derived classes must declare all redefined virtual functions within them, and derived classes can add virtual before such functions, but they do not have to.

When a virtual function is called through a pointer or reference, the compiler produces code that knows the runtime to determine which version of the function should be called. The called function is the one that matches the dynamic type of the object that is bound to the pointer or reference.

The call is resolved at run time only if the virtual function is called with a pointer or reference.

In the new C++11 standard we can use the Override keyword to illustrate virtual functions in derived classes. The advantage of doing this is to make the programmer's intentions clearer while the compiler can find some errors for us.

Virtual inheritance is a unique concept in multiple inheritance See Programmer interview Treasure P144

Virtual functions and virtual inheritance

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.