[ACCEPTED]-How do you make a prototype of a function with parameters that have default values?-c++

Accepted answer
Score: 28

You should put the default arguments in 7 the prototype, not the definition like this:

void arryprnt(int[] a, string intro, int len, string sep=", ", string end=".");

and 6 the make the definition without them:

void arryprnt(int[] a, string intro, int len, string sep, string end) {
    // ...
}

BTW: on 5 another note. It is considered good practice 4 to pass objects which larger than an int 3 by const reference. While this isn't appropriate for all situations, it 2 is appropriate for most and avoids copying 1 things unnecessarily. For example:

void func(const std::string &s) {
    // do some read-only operation with s.
}

func("hello world");

More Related questions