According to C++ Reference Operator[] of std::vector has 2 variants
reference operator[] (size_type n);
const_reference operator[] (size_type n) const;
When we execute the following line which of the above variant gets called?
std::vector<int> vlist;
vlist[0] = 7;
My thought, the 1st variant should not be called as I am assigning rvalue to an non-const lvalue reference, the way int& x = 7;
is illegal.
Aucun commentaire:
Enregistrer un commentaire