7.8 overload Functions

Source: Internet
Author: User

1. Any program has only one main function instance, and the main function cannot be reloaded.

2. functions cannot be overloaded only based on different return types.

3. overload and scope

  1. String getstring ();
  2. Void showstring ()
  3. {
  4. String getstring = "OK ";
  5. String S = getstring (); // error blocked!
  6. Cout <s;
  7. }

4. Reload the following three steps:

  1. Void F ();
  2. Void F (INT );
  3. Void F (INT, INT );
  4. Void F (double, double = 3.14 );
  5. F (5.3 );

1. Candidate Functions

2. Determine the feasible function: F (INT) f (double, double)

3. Find the best match.

Exact matching is better than matching F (double, double) that requires type conversion)

4. Reload determination with multiple real parameters

1). Matching of each real parameter is not inferior to matching required by other feasible functions.

2). At least one real Parameter Match is better than the match provided by other feasible functions (I am crazy)

5. Matching that requires type conversion "inferior to" matching that requires type improvement

You cannot pass an integer type to an enumeration-type parameter,

However, you can pass the enumerated parameters to the shaping parameters.

6. overload and const Parameters

This parameter is affected only when it is a reference or pointer.

It cannot be overloaded based on whether the pointer is const.

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.