vendredi 8 novembre 2019

Why const reference is allowed to assign a value but non const isn't? [duplicate]

This question already has an answer here:

  1. const int& i = 5;
  2. int& i = 5;

Why the 1st line is allowed but the 2nd line isn't? The explanation for the second may be that we can't assign a rvalue to a lvalue reference. Is it correct?

Aucun commentaire:

Enregistrer un commentaire