I would like to know, when someone gives you a template for a default constructor in C++ and in the parameter there is a series of unnamed variables that somehow are assigned values. What does this mean?
Is this legal?
How can one access these variables?
Example I received:
IntSet::IntSet(int = -1, int = -1, int = -1, int = -1); //default constructor
I would appreciate any answers that clarify this use!
That means that if you call it without passing parameters, the parameters will take the values you passed.
So if you call
would be equivalent to calling
About the unnamed part. I would assume because it is part of a library that uses templates. The nameless parameters are not used, but are there so it matches the signature of another class that may need them. In the case that it needs them, it will just pass -1 by default.
You can take a look at this link for an example:
http://compgroups.net/comp.lang.c++/unnamed-formal-parameter/1004784
I am copying the example from the above reference here, to make the case for using such a construct in an useful way
For instance
C::create would not compile unless A::A had a parameter even though it is
not used.