How to create a prototype of a function with parameters that have default values?

A have function with prototype:

void arryprnt(int[], string, int, string, string);

And the definition:

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

And I call it this way:

arryprnt(jimmy, "PSEUDOJIMMY: ", 15);

... when I make this call to arryprnt, I get a compiler error saying that I used too few arguments based on what the prototype says. β€œGood,” I thought, β€œthe compiler does not know that some arryprnt parameters have default values. I just copy the parameters from the definition to the prototype.” And I did, however, I got a compiler error telling me that I was calling arryprnt with too many arguments! I can just specify all the arguments, but is there a way to call it without specifying all the arguments?

+5
source share
1

, , :

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

:

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

: . , , int const. all, . :

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

func("hello world");
+20

All Articles