重新定义默认参数:参数4 [英] Redefinition of default parameter : parameter 4

查看:85
本文介绍了重新定义默认参数:参数4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译时我得到默认参数的错误重新定义:参数4



我尝试过:



我已编译但无效

When compile I get the error redefinition of default parameter : parameter 4

What I have tried:

I have compiled , but did not work

推荐答案

您必须仔细阅读发生错误的代码行。我猜你在标题声明中有一个默认参数不仅而且在代码实现中也是如此。



仅使用默认参数在声明中。如果它没有解决问题,则提供所有相关代码和完整的错误消息文本。
You must carefully read the codeline where the error is happening. I guess that you have an default parameter not only in the header declaration but also in the code implementation.

A default parameter is only used in the declaration. If it doesnt solve the problem provide all related code and the full error message text.


[更新,感谢 Richard ]

C ++默认参数 [ ^ ]必须在函数(或方法)中指定 函数(或方法)定义中的声明

声明和定义中指定它是一个错误。

首选方法是仅在函数(或方法)中指定它声明





例如

[updated, thanks to Richard]
C++ default arguments[^] must be specified either in function (or method) declarations or in function (or method) definitions.
Specifying it in both declaration and definition is an error.
The preferred approach is specifying it only in function (or method) declarations.


For example
// function declarations
int my_add( int a, int b =  5);
int my_sub( int a, int b = -1);
// ..
// function definitions
int my_add( int a, int b = 5) //<- WRONG, default parameter repeated in function definition
{
  return (a + b);
}
int my_sub( int a, int b) //<- fine
{
  return (a -b);
}



[/ update]


这篇关于重新定义默认参数:参数4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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