【发布时间】:2020-10-14 04:46:28
【问题描述】:
我想通过地址比较两个对象。我尝试了运算符重载,它似乎不适用于指针,但适用于对象本身。以下是相关代码:
class C {
public:
int x;
};
.
.
.
bool operator <( C *ptr_c1, C *ptr_c2 )
{
return ( (*ptr_c1).x < (*ptr_c2).x );
}
【问题讨论】:
-
@snjv:你是说给
C的指针你想比较它们,但是比较是基于一些成员,比如x? -
是的,这正是需要!
标签: c++ operator-overloading pointers