C + + override keyword

Source: Internet
Author: User

Description: The override reserved word indicates that the current function overrides the virtual function of the base class.

Objective: 1. In the case of more functions, you can prompt the reader that a function overrides the base class virtual function (which means that the virtual function is inherited from the base class, not the derived class itself); 2. Forces the compiler to check whether a function overrides the base class virtual function, and if not, an error.

Usage: Add the keyword after the member function parameter list of the class.

Example:
Class Base {
virtual void f ();
};

Class Derived:public Base {
void f () override; Represents a derived class overriding the base class virtual function f
void f () override;//error: Function F does not override any virtual function of base class
};

Note: Override is only a C + + reserved word, not a keyword, which means that only the correct use of the location, oerride the "keyword" function, other places can be used as a marker (such as: int override; is legal).

Related: Override also has a sister reserved word final.

C + + override keyword

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.