reference variable

后端 未结 3 1156
感情败类
感情败类 2021-01-19 16:13

In some text it is given that we can\'t assign constant values to a reference variable. When I executed such a program I could do it. Is there any condition we can\'t assign

3条回答
  •  日久生厌
    2021-01-19 16:53

    You cannot assign a constant value to a non-constant reference, the same way you could not assign a constant value's address to a pointer pointing to a non-constant value.

    At least, not without a const_cast.

    Edit: If you were actually referring to literal values, Luc's answer is the better one. I was referring to const variables, not literals.

提交回复
热议问题