const vector implies const elements?

后端 未结 4 950
难免孤独
难免孤独 2021-02-05 00:11
4条回答
  •  离开以前
    2021-02-05 00:39

    Yes, a const vector provides access to its elements as if they were const, that is, it only gives you const references. In your second function, it's not the objects of type A that are const, but pointers to them. A pointer being const does not mean that the object the pointer is pointing to is const. To declare a pointer-to-const, use the type A const *.

提交回复
热议问题