例如,我有这个课:
class example{
public:
int beauty;
void CompareObject(const example& another_object, example*& ptr);
};
方法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?
}
最佳答案
this
是对象的方法内部的对象地址。