I have a C ++ function called minhaFuncao()
declared like this:
minhaFuncao(int x, int y, float a);
and implemented like this:
minhaFuncao(int x, int y, float a=0){
...
}
What I'm trying to say is, when I call minhaFuncao
and pass the actual parameters to it, I wanted to be able to omit some parameters, that is, if I do not pass the actual parameter, the formal parameter receives the value that already it was assigned as float a=0
, I think of something like this:
minhaFuncao(1, 1);
Notice that I did not pass the actual parameter that would be assigned to float a
, so what I wanted was for it not to be passed to receive "0" or any other default value previously written to the function implementation. But if I decide to pass, that it normally receives, as below:
minhaFUncao(1, 1, 1.5);
Now realize that I passed the actual parameter "1.5" to float a
, I needed it to be "1.5" now instead of "0" set as the default.
There is some way to do this in C ++, I remember I already read it, but I'm not finding it at all, I do not know what words to use to search.
One thing I noticed is that if there is a way to do this, it will have its limitations, as the function implemented below would not be possible:
minhaFuncao(int x, int y, float a=0, int b, int c=0){
...
}
I think one of the rules for this would be that only the final parameters could be omitted, like this:
minhaFuncao(int x, int y, float a, int b=0, int c=0){
...
}
Because at the time of calling minhaFuncao()
, in the first form, it would go wrong, it would not know what is being omitted or not, so that would have to have this rule, or a way to specify all parameters at the time of passing the real ones like this:
minhaFuncao(x=1, y=1, b=1, c=1);
here I omitted the float a
parameter. What's the right way to do this in C ++ if it's possible?