且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++:指向对象的指针

更新时间:2023-11-28 11:20:58

>


I would like to compare two objects through their addresses. I tried operator overloading and it does not seem to work for pointers, but works for objects themselves. The following is the relevant code:

class C {
        public:
                int x;
};
.
.
.
bool operator <( C *ptr_c1, C *ptr_c2 )
{
        return ( (*ptr_c1).x < (*ptr_c2).x );
}

See these: