你好,我有以下代碼:的std :: make_pair與C++ 11
bool PinManager::insertPin(const std::string& p_pinNumber, const std::string& p_mode)
{
boost::shared_ptr<GPIOPin> pin(new GPIOPin(p_pinNumber, p_mode));
if (pin)
{
m_pinsInUse.insert(std::make_pair<std::string, boost::shared_ptr<GPIOPin> >(p_pinNumber, pin));
return true;
}
return false;
}
此代碼一直編譯,但是當我加入了-std=c++0x
將此代碼失敗的消息編譯:
[ 42%] Building CXX object gpioaccess/CMakeFiles/gpioaccess.dir/pinmanager/pinmanager.cpp.o
/home/pi/robot_2.0/trunk/gpioaccess/pinmanager/pinmanager.cpp: In member function 'bool gpioaccess::PinManager::insertPin(const string&, const string&)':
/home/pi/robot_2.0/trunk/gpioaccess/pinmanager/pinmanager.cpp:39:101: error: no matching function for call to 'make_pair(const string&, boost::shared_ptr<gpioaccess::GPIOPin>&)'
/home/pi/robot_2.0/trunk/gpioaccess/pinmanager/pinmanager.cpp:39:101: note: candidate is:
/usr/include/c++/4.6/bits/stl_pair.h:262:5: note: template<class _T1, class _T2> std::pair<typename std::__decay_and_strip<_T1>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&)
gpioaccess/CMakeFiles/gpioaccess.dir/build.make:77: recipe for target 'gpioaccess/CMakeFiles/gpioaccess.dir/pinmanager/pinmanager.cpp.o' failed
make[2]: *** [gpioaccess/CMakeFiles/gpioaccess.dir/pinmanager/pinmanager.cpp.o] Error 1
CMakeFiles/Makefile2:75: recipe for target 'gpioaccess/CMakeFiles/gpioaccess.dir/all' failed
make[1]: *** [gpioaccess/CMakeFiles/gpioaccess.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2
經過一番小小的挖掘,我發現之前編譯的這個事實可能是一個bug;不過,我仍然不確定如何解決這個問題。有沒有人有正確的方向?
gcc --version
是gcc (Debian 4.6.3-14+rpi1) 4.6.3
'make_pair'應該能夠推斷出參數類型,試着刪除你明確的模板參數:'std :: make_pair(p_pinNumber,pin)' – melak47
注意:'if(pin)'總是爲true或者沒有影響如果拋出異常 –
@ melak47這是刪除參數允許代碼編譯的問題。謝謝! – joshu