Effective C + + clause 36 never redefine inherited non-virtual functions

Source: Internet
Author: User

1. Public inheritance implies a is-a relationship, that is, a derived class is one of the base classes, and any operation derived classes that can be performed by a base class should also be possible, if the derived class is different from the base class for the implementation of a function, then the function should be set to virtual. If a function in the base class is non-virtual, it should also mean that the derived class should inherit the implementation of the function and should not redefine it.

2. Because the Non-virtual function takes a static binding, if it is redefined, the non-virtual function that is called by the base-class pointer to the derived class object will be the base-class version, which is different from the expectation, so override is set to virtual. Do not override when set to Non-virtual.

Effective C + + clause 36 never redefine inherited non-virtual functions

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.