The member begin has two overloadings one of them is const_iterator begin() const;
. There's also the cbegin const_iterator cbegin() const noexcept;
. Both of them returns const_iterator
to the begin of a list. What's the difference?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
begin
will return an iterator
or a const_iterator
depending on the const-qualification of the object it is called on.
cbegin
will return a const_iterator
unconditionally.
std::vector<int> vec;
const std::vector<int> const_vec;
vec.begin(); //iterator
vec.cbegin(); //const_iterator
const_vec.begin(); //const_iterator
const_vec.cbegin(); //const_iterator