C ++ Default argument error

Any idea why this error occurs at compile time?

ComplexNumber.cpp:21: error: default argument given for parameter 1 of 'void ComplexNumber::print(std::ostream&) const' ComplexNumber.h:17: error: after previous specification in 'void ComplexNumber::print(std::ostream&) const' 

Here is my code in these specific areas:

ComplexNumber.cpp

 21 void ComplexNumber::print(ostream & out = cout) const { 

ComplexNumber.h

 17 void print(ostream & out = cout) const; 
+7
source share
1 answer

You should only specify the default parameter in the function declaration, i.e. in the title. You should look something like this:

 void ComplexNumber::print(ostream & out) const { ..... } 
+18
source

All Articles