本文介绍了C ++:指向对象的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过他们的地址比较两个对象。我试过操作符重载,它似乎不工作的指针,但工作对象本身。以下是相关代码:
class C {
public:
int x;
};
。
。
。
bool operator<(C * ptr_c1,C * ptr_c2)
{
return((* ptr_c1).x<(* ptr_c2).x);
}
解决方案
>
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:
- Universal
less<>
for pointers in C++ standard - What are the operations supported by raw pointer and function pointer in C/C++?
这篇关于C ++:指向对象的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!