矢量<int &> 不编译
vector<int &> not compiling
问题来自下面的代码:
vector<int &> one; //compile failed
我很困惑为什么代码不编译
不能直接使用引用向量
但是你可以使用std::reference_wrapper
来达到你想要的结果。
可能重复Why can't I make a vector of references?(我目前没有代表来标记它)。
STL容器必须保存可赋值的类型,而引用不能赋值。
问题来自下面的代码:
vector<int &> one; //compile failed
我很困惑为什么代码不编译
不能直接使用引用向量
但是你可以使用std::reference_wrapper
来达到你想要的结果。
可能重复Why can't I make a vector of references?(我目前没有代表来标记它)。
STL容器必须保存可赋值的类型,而引用不能赋值。