How to distinguish between overload, overwrite, and hide functions in C ++

Source: Internet
Author: User

The key difference lies in the scope of occurrence and the virtual keyword.
I. Conditions for overload: (1) the same range (in the same class); (2) the same function name; (3) Different parameters (different numbers or types ); (4) It is irrelevant to the virtual keyword.
2. The conditions for overwriting are as follows: (1) different scopes (the two functions are in the base class and derived class respectively); (2) the function names are the same; (3) the parameters are the same; (4) basic functions must have virtual keywords.
3. The hidden condition is divided into two situations (hiding means that the function of the derived class shields the base class function with the same name)
The condition in the first case: This is similar to the overload. I call it "pseudo-overload" because it is the only difference from the overload is the scope of occurrence. (1) different scopes (the two functions are located in the base class and the derived class respectively); (2) the same function name; (3) Different parameters (different numbers or types); (4) it is irrelevant to the virtual keyword.
Condition 2: This is similar to overwrite. I call it "pseudo overwrite" because it is different from overwrite because there is no virtual keyword. (1) different scopes (the two functions are located in the base class and derived class respectively); (2) the same function name; (3) the same parameter; (4) basic functions cannot have virtual keywords.

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.