需求

今天编译时,报错: =error: binding reference of type ‘CalibrationVoltage::RefFloat_kParamNum’ {aka ‘float (&)[3]’} to ‘const float [3]’ discards qualifiers=, 我觉得很奇怪,我明明加了 const 了,为啥还是说没有 const 呢?

using RefFloat_kParamNum = float (&) [kParamNum];

RefFloat_kChannelNum_kParamNum CalibrateParam(const RefFloat_kParamNum output);

解决

怀疑是因为 constusing 一起作用的结果,所以稍微修改了一下,就 ok 了。根本原因要等后续再查了。

using RefFloat_const_kParamNum = const float (&) [kParamNum];

RefFloat_kChannelNum_kParamNum CalibrateParam(RefFloat_const_kParamNum output);

参考

C++编译出现binding ‘const string {aka const std::__cxx11::basic_string<char>}’ to reference of type ‘std

error: binding reference of type int& to const int discards qualifiers

引用、const引用和非const引用