8

知道为什么在编译时会出现此错误吗?

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’

这是我在这些特定区域的代码:

复数.cpp

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

复数.h

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

1 回答 1

21

您应该只在函数声明中指定默认参数,即在标题中。你的实现应该是这样的:

void ComplexNumber::print(ostream & out) const { ..... }
于 2012-04-25T20:53:13.050 回答