C ++缺省参数错误 [英] C++ Default Argument Error

查看:340
本文介绍了C ++缺省参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何想法为什么这个错误会在编译时出现?

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

ComplexNumber.cpp

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

ComplexNumber.h

ComplexNumber.h

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


推荐答案

您应该只在函数声明中指定默认参数,即在报头中。您的实现应该看起来像这样:

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 { ..... }

这篇关于C ++缺省参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆