编译错误:error: default argument given for parameter 1 of ‘’
来源:互联网 发布:类似知乎的平台 编辑:程序博客网 时间:2024/05/17 08:47
[+]
问题:
编译时出现错误提示如下:
- u1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/src/trunk$ make
- g++ -g3 -Wall -o0 -c ini_file.cpp -o ini_file.o
- ini_file.cpp:17:117: error: default argument given for parameter 1 of ‘IniFile::IniFile(const string&, std::string, std::string, std::string)’ [-fpermissive]
- ini_file.h:15:14: error: after previous specification in ‘IniFile::IniFile(const string&, std::string, std::string, std::string)’ [-fpermissive]
- ini_file.cpp:17:117: error: default argument given for parameter 2 of ‘IniFile::IniFile(const string&, std::string, std::string, std::string)’ [-fpermissive]
- ini_file.h:15:14: error: after previous specification in ‘IniFile::IniFile(const string&, std::string, std::string, std::string)’ [-fpermissive]
- ini_file.cpp:17:117: error: default argument given for parameter 3 of ‘IniFile::IniFile(const string&, std::string, std::string, std::string)’ [-fpermissive]
- ini_file.h:15:14: error: after previous specification in ‘IniFile::IniFile(const string&, std::string, std::string, std::string)’ [-fpermissive]
- ini_file.cpp:17:117: error: default argument given for parameter 4 of ‘IniFile::IniFile(const string&, std::string, std::string, std::string)’ [-fpermissive]
- ini_file.h:15:14: error: after previous specification in ‘IniFile::IniFile(const string&, std::string, std::string, std::string)’ [-fpermissive]
- make: *** [ini_file.o] Error 1
- 1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/src/trunk$
- IniFile::IniFile(const string& filename, const string delim, const string sec_delim_l, const string sec_delim_r)
- : ini_filename_(filename), delim_(delim), sec_delim_l_(sec_delim_l), sec_delim_r_(sec_delim_r), is_dirty_(false), is_saved_(false) {
- Load(ini_filename_);
- }
- class IniFile {
- public:
- IniFile(const string& filename = "", const string delim = "=", const string sec_delim_l = "[", const string sec_delim_r = "]");
- ~IniFile();
- };
解决办法:
1. 原因肯定是由于构造函数使用默认参数造成的。
C++规则,只可能对排列在最后的那些参数提供默认参数,本程序并未违反这一个规则。
查看《C++程序设计语言(特别版)》第202~203页,类Date的声明中构造函数同时声明了缺省参数,而在构造函数的定义中则没有再次声明缺省参数。
参照Date类使用缺省参数的方式,将构造函数定义中的缺省参数声明清除,再次编译,成功通过。
- u1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/src/trunk$ make
- g++ -g3 -Wall -o0 -c main_ctrl.cpp -o main_ctrl.o
- g++ -o local_ctrl main_ctrl.o msgrcv_cmd.o controller.o thread.o ini_file.o dataparse.o msgsnd_data.o sensor_reader.o cJSON.o -L../../drivers -lpthread -lphysicalop -lm
- u1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/src/trunk$
问题解决。
进一步的结论:既可以在类的声明中,也可以在函数定义中声明缺省参数,但不能既在类声明中又在函数定义中同时声明缺省参数。
参考地址:http://stackoverflow.com/questions/13295530/this-is-a-new-compile-error-for-me
- 编译错误:error: default argument given for parameter 1 of ‘’
- 编译错误:error: default argument given for parameter 1 of ‘’ [-fpermissive]
- C++编译错误:error: default argument given for parameter... [-fpermissive]
- Debug:error:default argument given for parameter
- C++ error: default argument given for parameter 1
- default argument given of parameter 的问题
- default argument given of parameter 的问题
- 错误: default argument missing for parameter 2 of
- error: default argument given for parameter 2 默认的参数只能给一次
- 编译错误error C2587: '_U' : illegal use of local variable as default parameter的问题
- redefinition of default parameter : parameter 1
- error C2572: 'xxxx' : redefinition of default parameter : parameter 5 解决办法
- No parameter name specified for argument of type
- redefinition of default parameter
- Error 1 Inconsistent accessibility: parameter type 编译错误
- Error 1 Inconsistent accessibility: parameter type 编译错误
- Python 'takes exactly 1 argument (2 given)' Python error
- Python 'takes exactly 1 argument (2 given)' Python error
- 汉化Eclipse+配色方法(官方语言包)
- 如何删除DataGridView表格中的选中的当前行
- Hibernate中的unsaved-value
- Restrictions用法
- Android开发中常用的颜色收集整理
- 编译错误:error: default argument given for parameter 1 of ‘’
- hive命令参数
- java程序中调用linux命令
- 全球首款3D浏览器--Venus
- oracle查询表 索引、唯一约束、字段等相关信息
- 毕业后五年拉开大家差距的原因
- cocos2d 坐标系统
- Oracle数据库的冷备份及冷备份异地恢复方法
- Google开源项目ZXing(二维条码编解码)简单使用(Java版)