哪个是正确的:vector< const string>或const vector< string>吗? [英] Which is correct: vector<const string> OR const vector<string>?
问题描述
哪个是正确的: vector< const string>
或 const vector< string>?
我想创建一个 std :: string
s的 std :: vector
,并且我不会对其进行更改.但是我不确定这两种方式中哪种更好,为什么呢.
I want to create an std::vector
of std::string
s, and I won't make changes to it.
But I am not sure which of the two ways is better and why.
推荐答案
如果您的唯一选择是这两个,并且希望编译程序,请使用 const std :: vector< std :: string>
.
If your only choices are those two and you want the program to compile, use const std::vector<std::string>
.
如果您不介意编译错误(在 GCC4.8 和 Clang ),可能是由于 const std :: string
不符合 CopyAssignable (在C ++ 11之前)的要求,或者 MoveAssignable (自C ++ 11起),即使 Destructible
,请使用 std :: vector< conststd :: string>
.
If you don't mind compilation errors (both on GCC4.8 and Clang), probably due to the fact that const std::string
does not meet the requirement of CopyAssignable (prior to C++11) or MoveAssignable (since C++11), even though, apparently, it's mostly because it's not Destructible
, use std::vector<const std::string>
.
这篇关于哪个是正确的:vector< const string>或const vector< string>吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!