conststd::vector<T>和std::vector<T>const有什么区别?

我认为声明 a 的唯一方法const<vector>是:

const std::vector<T> v; 

回答

const 适用于它左边的东西,除非左边没有任何东西,然后它适用于它右边的东西。

所以,const int a=1;int const a=1;是相等的。

const int *bint const *b相等(指向常量的指针int),但与 不同int * const b,后者是指向非常量的常量指针int

这适用于所有数据类型,我选择int它是因为它比std::vector<T>.

  • And the West Const/East Const battle still continues to this day....
  • "`const` goes to the left" is ambiguous; it can mean "`const` applies to whatever is on its left" as you intended, but it can also mean "`const` should be written to the left of whatever it should apply to", which is wrong. Better to write "`const" applies to the thing to its left` or something like that, and similar with right.

以上是conststd::vector&lt;T&gt;和std::vector&lt;T&gt;const有什么区别?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>