Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between const std::vector<T> and std::vector<T> const?

I thought the only way to declare a const<vector> is:

const std::vector<T> v; 
like image 231
RRRRyk Avatar asked Mar 03 '21 15:03

RRRRyk


1 Answers

const applies to the thing to its left, except for when there is nothing on the left then it applies to the thing to its right.

So, const int a=1; and int const a=1; are equal.

const int *b and int const *b are equal (pointer to a constant int), but different to int * const b, which is a constant pointer to a non-constant int.

This applies to all data types, I choose int because it is easier to type than std::vector<T>.

like image 119
mch Avatar answered Sep 18 '22 05:09

mch