Why this is causing C2102: '&' requires l-value

前端 未结 5 1356
无人共我
无人共我 2021-01-02 12:16

I was wondering, why the following way of code (Already commented out) will cause
C2102: \'&\' requires l-value

Is there a better way to avoid u

5条回答
  •  被撕碎了的回忆
    2021-01-02 12:46

    You could instead define:

    int **get_dummy() ... return &dummy;
    

    You can think of an r-value as an expression, essentially, whereas an l-value is an actual object. Expressions don't have addresses, and even if they did, it's hard to imagine what good the address would be. It's easy to understand how the address of an object can be useful.

    It's a bit hard to understand an issue like this abstractly. The very best way to develop an understanding of pointers and compiled languages is to learn assembly language.

提交回复
热议问题