construction const parameter问题 构造函数const引用参数问题

时间:2022-12-05 23:23:31

工程在window下编译没有任何问题, 但是在linux(CentOS6)下编译就老是报错

C++ 编译器已升级到最新版 6.1.0

错误如下:

In file included from /usr/local/include/c++/6.1./bits/stl_algobase.h::,
from /usr/local/include/c++/6.1./bits/char_traits.h:,
from /usr/local/include/c++/6.1./string:,
from CTIServer.h:,
from CTIServer.cpp::
/usr/local/include/c++/6.1./bits/stl_pair.h: In instantiation of ‘struct std::pair<const std::__cxx11::basic_string<char>, ExtUsrInfo>’:
CTIServer.cpp::: required from here
/usr/local/include/c++/6.1./bits/stl_pair.h::: 错误:‘constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const std::__cxx11::basic_string<char>; _T2 = ExtUsrInfo]’被声明为取常量引用,但是隐式声明取非常量引用
constexpr pair(const pair&) = default;
^~~~
/usr/local/include/c++/6.1./bits/stl_pair.h: In instantiation of ‘struct std::pair<const std::__cxx11::basic_string<char>, Confrence>’:
CTIServer.cpp::: required from here
/usr/local/include/c++/6.1./bits/stl_pair.h::: 错误:‘constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const std::__cxx11::basic_string<char>; _T2 = Confrence]’被声明为取常量引用,但是隐式声明取非常量引用
make: *** [CTIServer.o] 错误

 不管怎么改都是报这个错误,

感觉过不去这个坎了~~~

错误源代码就是在这一行,中间的不等于表达式:

for(pos=m_ExtUsrInfoList.begin();pos!=m_ExtUsrInfoList.end();pos++)

 然后 , 因为升级到C++11了嘛,改用 for:auto 方式循环,还是一样这一行报错, 折腾的没门 ,

于是怀疑C++11的问题?

于是 找了个 C++没升级的试试,结果如下:

In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4./../../../../include/c++/4.4./bits/stl_algobase.h:,
from /usr/lib/gcc/x86_64-redhat-linux/4.4./../../../../include/c++/4.4./bits/char_traits.h:,
from /usr/lib/gcc/x86_64-redhat-linux/4.4./../../../../include/c++/4.4./string:,
from CTIServer.h:,
from CTIServer.cpp::
/usr/lib/gcc/x86_64-redhat-linux/4.4./../../../../include/c++/4.4./bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _T2 = ExtUsrInfo]’:
/usr/lib/gcc/x86_64-redhat-linux/4.4./../../../../include/c++/4.4./bits/stl_map.h:: instantiated from ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = ExtUsrInfo, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, ExtUsrInfo> >]’
CTIServer.cpp:: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4./../../../../include/c++/4.4./bits/stl_pair.h:: 错误:对‘ExtUsrInfo::ExtUsrInfo(const ExtUsrInfo&)’的调用没有匹配的函数
CTIServer.h:: 附注:备选为: ExtUsrInfo::ExtUsrInfo(ExtUsrInfo*)
CTIServer.h:: 附注: ExtUsrInfo::ExtUsrInfo(ExtUsrInfo&)
CTIServer.h:: 附注: ExtUsrInfo::ExtUsrInfo()

看到后面

错误:对‘ExtUsrInfo::ExtUsrInfo(const ExtUsrInfo&)’的调用没有匹配的函数
CTIServer.h:56: 附注:备选为: ExtUsrInfo::ExtUsrInfo(ExtUsrInfo*)
CTIServer.h:55: 附注: ExtUsrInfo::ExtUsrInfo(ExtUsrInfo&)
CTIServer.h:54: 附注: ExtUsrInfo::ExtUsrInfo() 貌似终于发现了点什么, 哈哈, 你妹的, 构造函数没有 参数 是const类型的
const ExtUsrInfo&
!!!!

终于找到了,  但是还得感谢C++4.4.7 版本的 错误提示,  C++11 的错误 还是难看懂!~

PS:  linux下的 编译检查 要比 window下 的(VS) 严格得多啊!~