Why does std::vector::front has two definitions? (C++) -


this question has answer here:

i'm c++ newbie. tell me why std::vector::front has 2 definitions, how different, , how each of them called?

the function seems have 2 definitions,

  • reference front();
  • const_reference front() const;

i noticed these 2 definitions, when looked function on web. following 2 web sites seem same 2 definitions.

http://www.cplusplus.com/reference/vector/vector/front/

http://en.cppreference.com/w/cpp/container/vector/front

the const version used const this pointer due overload resolution. not sensible if non-const object returned, since hack round constness.

the non-const version used non-const this pointer. object can modify.

we call const correctness.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -