简体   繁体   English

重新定义默认参数

[英]Redefinition of default argument

I have encounter an error saying "redefinition of default argument" while I am compiling some codes. 在编译某些代码时,我遇到了一个错误,说“重新定义默认参数”。 This is the line that is throwing the error: 这是抛出错误的行:

bool wCommandDistributor::initialise (const bool server = true, const short ncmds=0,
                byte (*cmds)[CMD_MAX_RECLEN] = (byte (*)[CMD_MAX_RECLEN])0)

Is there anyway that I can rewrite the code in order to solve the error? 无论如何我是否可以重写代码以解决错误? This is not a code written by me. 这不是我写的代码。 I am helping to rewrite the code and it is written in C++. 我正在帮助重写代码,它是用C ++编写的。

Thanks in advance. 提前致谢。

The compiler says it all, you are redefining the default arguments of initialise (even though they might be the same). 编译器说明了这一切,你正在重新定义initialise的默认参数(即使它们可能是相同的)。

The default arguments were probably already defined in the function declaration. 默认参数可能已在函数声明中定义。 You don't need to redefine them in the function definition, and so you should remove them. 您不需要在函数定义中重新定义它们,因此您应该删除它们。

But only the ones that were already defined in the declaration, it might be that some were not defined in the declaration, only in the definition. 但只有已在声明中定义的那些,可能是某些在声明中定义,仅在定义中定义。 In this case you should naturally leave them. 在这种情况下,你应该自然地离开它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM