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.
the const
version used const
this
pointer due overload resolution. not sensible if non-const
object returned, since hack round const
ness.
the non-const
version used non-const
this
pointer. object can modify.
we call const correctness.
Comments
Post a Comment