运维调试记录:C++ compile error: default argument given for parameter

迷南。 2022-07-26 00:21 181阅读 0赞

问题:

编译C++代码时出现错误提示如下:

  1. > g++ *.cpp
  2. fileTest.cpp:17:117: error: default argument given for parameter 1 of MyClass::fileTest(const string&, std::string, std::string, std::string)’ [-fpermissive]
  3. fileTest.h:15:14: error: after previous specification in MyClass::fileTest(const string&, std::string, std::string, std::string)’ [-fpermissive]

解决办法:

既可以在类的声明中,也可以在函数定义中声明缺省参数,但不能既在类声明中又在函数定义中同时声明缺省参数。

You can declare default arguments in the class declaration or in the function definition, but not both.

因此,将定义或声明中的任一个缺省参数删除即可。

参考网址

http://stackoverflow.com/questions/13295530/this-is-a-new-compile-error-for-me

发表评论

表情:
评论列表 (有 0 条评论,181人围观)

还没有评论,来说两句吧...

相关阅读