How do you create an optional parameter in a class method?

Asked

Viewed 169 times

2

I know that to create an optional parameter in a function you can do this:

void exemplo(int a,int b=0);

But how do I do it in a class function
ex:

class Exemplo{
    public:
    void nada(int,int);
};
void Exemplo::nada(int a,int b){}

This would be an example with "normal" parameters, to try to leave the optional (b) I did:

void Exemplo::nada(int a,int b=0){}

but when calling the compiler function says I need to put (b), probably because in that statement it is not optional:

void nada(int,int);

How can I solve this problem, remembering that I do not want a constructor with optional parameters but another function.

1 answer

2


  • Thanks @Maniero now ta working I had tried something similar doing void nothing(int a, int b = 0); only then I was doing void Example::nada(int a, int b=0) so it was going wrong.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.