Here is my class definition:
class MyClass {
public:
void test(int val = 0);
}
void MyClass::test(int val = 0) {
//
}
When I try to compile this code I get the error: "default parameter given for parameter 1"
It's just a simple function, I don't know what's wrong. I'm using Eclipse + MinGW.
Formally, you can specify the default argument wherever you want, but you can do it only once per parameter. Even if the value is the same, it has to be specificed either in the function declaration or in the definition, but not in both.
Of course, if the declaratuion is in the header file (and the definition is in implementation file), the common sense says that the default argument has to be specified in the header file, so that all translation units can "see" it.
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