C++ Default Argument Error

2020-02-13 23:20发布

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;

1条回答
虎瘦雄心在
2楼-- · 2020-02-13 23:54

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 { ..... }
查看更多
登录 后发表回答