例如我有这样的课程:
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)