I want to pass the variable a as a default parameter in method func().
struct S {
int a;
int func(int b = a) {
// do something
}
};
On compiling it shows error. Is it possible to somehow get around this?
It is not possible to use the value of a non-static member as default argument. You can use an overload instead:
struct S {
int a;
int func(int b) {
// do something
}
int func() { return func(a); }
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With