user584583
user584583

Reputation: 1280

method calling in C++ / number parameters not matching

In reading other programmer's C++ code I am confused when the method takes 3 parameters, but the call to the method only passes one.

For example

.
.
CarList myCarList;
read_next(myCarList);
.
.
size_t CarListReader::read_next(CarList &cl, bool theBool, size_t skip)

In java I know of method overloading based on the method signature, but I am unclear what is going on in this case in C++.

Upvotes: 0

Views: 111

Answers (1)

JoeFish
JoeFish

Reputation: 3100

That's C++ code. If you find the function's prototype (maybe in a header file), you should see something like this:

size_t CarListReader::read_next(CarList &cl, bool theBool = true, size_t skip = 4);

Those are default arguments, and will be used if they are not supplied in the function call.

Your confusion probably comes from the fact that the default values are specified in the function prototype (which may be buried in a header file somewhere), not in the function definition. They will only be in the function definition if there is no prototype*).

*) in which case the function definition is the prototype alias declaration.

Upvotes: 10

Related Questions