Address of a reference

前端 未结 5 1182
北恋
北恋 2021-01-16 02:40

So I am having a discussion with a friend about reference and pointers.

What we got talking about is \"you can take an address of a pointer but you cant take an addr

5条回答
  •  独厮守ぢ
    2021-01-16 03:14

    By the time you apply the address-of operator in your example, there is no distinction between the reference and the real object anymore. The reference is the object.

    The rule instead applies at the moment you try to declare a pointer to a reference. Try it:

    int x = 0;
    int &*ptr = &x;
    

    Result with MSVC 2013:

    error C2528: 'ptr' : pointer to reference is illegal
    

提交回复
热议问题