以下の内容はhttps://toburau.hatenablog.jp/entry/20090604/1244116574より取得しました。


constその2 const_iterator

Effectvie C++ 第1章3項

STLiteratorでのconstの場合。iteratorの宣言にconstを付けるとiterator自体がconstとなり、参照先のデータはconstとはならず変更できる。

std::vector<int> v;

const std::vector<int>::iterator p = v.begin();
*p = 123; // これはOK
p++; // これはできない

参照先のデータを変更できないようにconstとするにはconst_iteratorを使う。

std::vector<int> v;

std::vector<int>::const_iterator p = v.begin();
*p = 123; // これはできない
p++; // これはOK



以上の内容はhttps://toburau.hatenablog.jp/entry/20090604/1244116574より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14