解决编译warning:warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
来源:互联网 发布:linux vim 保存 编辑:程序博客网 时间:2024/03/29 06:37
问题:
环境:ubuntu 12.04,g++版本4.6.3,编译目标文件时出现warnings:
u1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/src/trunk$ make clean;makerm -f *.o local_ctrlg++ -g3 -Wall -o0 -c msgrcv_cmd.cpp -o msgrcv_cmd.oIn file included from msgrcv_cmd.h:24:0, from msgrcv_cmd.cpp:30:controller.h: In constructor ‘MeteringUnit::MeteringUnit(size_t, double, double, double)’:controller.h:92:12: warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]controller.h:91:12: warning: ‘double MeteringUnit::current_gain_’ [-Wreorder]controller.h:77:5: warning: when initialized here [-Wreorder]g++ -g3 -Wall -o0 -c controller.cpp -o controller.oIn file included from controller.cpp:21:0:controller.h: In constructor ‘MeteringUnit::MeteringUnit(size_t, double, double, double)’:controller.h:92:12: warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]controller.h:91:12: warning: ‘double MeteringUnit::current_gain_’ [-Wreorder]controller.h:77:5: warning: when initialized here [-Wreorder]g++ -g3 -Wall -o0 -c thread.cpp -o thread.og++ -g3 -Wall -o0 -c ini_file.cpp -o ini_file.og++ -g3 -Wall -o0 -c main_ctrl.cpp -o main_ctrl.oIn file included from main_ctrl.cpp:25:0:controller.h: In constructor ‘MeteringUnit::MeteringUnit(size_t, double, double, double)’:controller.h:92:12: warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]controller.h:91:12: warning: ‘double MeteringUnit::current_gain_’ [-Wreorder]controller.h:77:5: warning: when initialized here [-Wreorder]
解决办法:
1. 出问题的地方在头文件controller.h中,
class MeteringUnit {public: MeteringUnit(size_t port_num = 1, double pgain = 1.0, double cgain = 1.0, double vgain = 1.0) : port_(port_num), power_gain_(pgain), voltage_gain_(vgain), current_gain_(cgain) { } ~MeteringUnit(); void Refresh(); double Power() const; double Current() const; double Voltage() const;private: size_t port_; operation* mu_op_; static const SensorType sensor_typ_ = EMETER;private: static const int emeter_pulse_const_ = 3200; double power_gain_; double current_gain_; double voltage_gain_; double power_; double current_; double voltage_;int gpqs1_;// GP1/GQ1/GS1(0x50/0x51/0x52)int gphs1_;// Gphs1(0x6d)int p1offset_;// P1offset(0x65)};从编译后的提示,已经可以很明白地看出错在什么地方了,
MeteringUnit::voltage_gain_应该在double MeteringUnit::current_gain_之后初始化。
也就是说,构造函数中变量初始化的顺序与该成员变量在类MeteringUnit中定义的顺序不一致。
将其中的两行
MeteringUnit(size_t port_num = 1, double pgain = 1.0, double cgain = 1.0, double vgain = 1.0) : port_(port_num), power_gain_(pgain), voltage_gain_(vgain), current_gain_(cgain) { }改为
MeteringUnit(size_t port_num = 1, double pgain = 1.0, double cgain = 1.0, double vgain = 1.0) : port_(port_num), power_gain_(pgain), current_gain_(cgain), voltage_gain_(vgain) { }重新编译,问题解决。
u1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/src/trunk$ make clean;makerm -f *.o local_ctrlg++ -g3 -Wall -o0 -c msgrcv_cmd.cpp -o msgrcv_cmd.og++ -g3 -Wall -o0 -c controller.cpp -o controller.og++ -g3 -Wall -o0 -c thread.cpp -o thread.og++ -g3 -Wall -o0 -c ini_file.cpp -o ini_file.og++ -g3 -Wall -o0 -c main_ctrl.cpp -o main_ctrl.og++ -o local_ctrl msgrcv_cmd.o controller.o thread.o ini_file.o main_ctrl.o -L../../drivers -lphysicalop -lpthread
- 解决编译warning:warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
- 嵌入式 解决编译warning:warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
- gcc warning "will be initialized after [-Wreorder]
- QT问题记录之warning: ‘xxx’ will be initialized after [-Wreorder]
- gcc compiler warning: “will be initialized after/when initialized here”
- gcc compiler warning: “will be initialized after/when initialized here”
- gcc warning:‘Test::b’will be initialized after
- will be initialized after [-Wreorder], 类成员构造顺序
- Warning::'XXX' will be initialized later
- 解决Warning中Wreorder
- will be initialized after
- xxx will be initialized after
- 解决QT中Warning中Wreorder
- WARNING: *** TIFF loader will not be built 的解决
- warning: LF will be replaced by CRLF
- warning: LF will be replaced by CRLF
- warning: LF will be replaced by CRLF
- warning: LF will be replaced by CRLF
- DOM4J介绍与代码示例
- 一线城市 or 二线城市
- 为oracle 11g hr用户解锁并修改密码
- hdu1408精度问题,好坑人啊
- ubuntu下用apt-get 安装PHP+MYSQL+Apache
- 解决编译warning:warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
- 一、Git手册--获取和创建项目(翻译自http://gitref.org/)
- 介绍CSS盒模型
- Android 修改Bitmap 图片像素的信息 R G B 颜色值 详解
- NBUT1482:嘛~付钱吧!(完全背包)
- my97 WdatePicker 使用大全
- Linux根文件系统结构再认识
- poj 1847
- 【deep learning学习笔记】Autoencoder