How to get a pointer from a reference?

后端 未结 6 881
野趣味
野趣味 2020-12-07 20:22

There seems to be many relavent questions talking about pointer vs. reference, but I couldn\'t find what I want to know. Basically, an object is passed in by a reference:

6条回答
  •  情话喂你
    2020-12-07 20:29

    Use the address-of (&) operator on the reference.

    &objRef
    

    Like any other operator used on a reference, this actually affects the referred-to object.

    As @Kerrek points out, since the operator affects the referred-to object, if that object has an overloaded operator& function, this will call it instead and std::address_of is needed to get the true address.

提交回复
热议问题