Pat Murray
Pat Murray

Reputation: 4285

C++ Default Argument Error

Any Idea why this error is coming up 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 at those certain areas:

ComplexNumber.cpp

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

ComplexNumber.h

17    void print(ostream & out = cout) const;

Upvotes: 8

Views: 4153

Answers (1)

juanchopanza
juanchopanza

Reputation: 227608

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

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

Upvotes: 21

Related Questions