提升元组和 stl 向量编译错误

Boost tuple and stl vector compilation error

本文关键字:向量 编译 错误 stl 元组      更新时间:2023-10-16

以下行不会编译错误:

No viable overloaded '='

std::string myString;
float myFloat;
boost::tuple<const std::string&, float> myTuple 
    = boost::tuple<const std::string&, float>(myString, myFloat);
std::vector<boost::tuple<const std::string&, float> > myVector;
myVector.push_back(myTuple);

有人有线索吗!?提示:如果我用一个简单的标准::字符串替换"const std::string&",一切都很好。

向量的成员必须是可复制的(C++98)或至少是可移动的(C++11)。引用不是。