如何知道方法中的对象地址?

Ema*_*rce 0 c++

例如我有这样的课程:

class example{
public:
       int beauty;
      void CompareObject(const example& another_object, example*& ptr);
};
Run Code Online (Sandbox Code Playgroud)

CompareObject() 方法将此对象与对象 another_object 进行比较(通过引用),并将最漂亮的对象的地址保存在指针 ptr 中(也是通过引用传递)

问题出在 CompareExampleObject 中:

void CompareExampleObject (const example& another_object, example*& ptr){
    // set the best object
    if(beauty < another_object.beauty)
        ptr = &another_object;
    else
        ptr = // !!! What should I write here?
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ica 5

this是对象方法内对象的地址。