About default arguments

Source: Internet
Author: User

Defines a function f (const string &str, Long pos, long Count =-1)

{

Do something

}

And there was an error in using it.

int main ()

{

String str;

Long pos = 1;

F (str, POS);

}

Tip Information is

Error 1 C2664: "String &string::f (const string &,long,long)": Parameter 1 cannot be converted from "string" to "long" c:\users\wlp\ source. CPP 8 1 String

Find out why books are found

"You can specify a default argument in a function declaration as well as in a function definition, but in one file, you can specify a default argument only once for one parameter, and two: if you provide a default argument in the formal parameter list of a function definition, the default argument is valid only if the function is called in the source file that contains the function definition."

I have defined f () in one file, but it is called in another file, so the default argument cannot be used

The default argument can be specified in the declaration, or it can be specified in the definition, but it is recommended to give the default parameter in the declaration, which is no longer given in the definition, because the function declaration is generally in the header file, so that the file containing the header file can use the default argument, otherwise only one file can be used.

About default arguments

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.