集如何区分对象?

小太郎*_*小太郎 1 c++ java set

集如何区分Java和C++中的对象?或者根本没有区分它们?

以这些为例:
C++

std::set<A> aset;
A a(1, 2); // Assume A has only two elements, and this constructor sets them both
aset.insert(a);
A a2(1, 2); // This would initialise a `A' object to the same values as `a', but a different object
aset.count(a2); // Would this return 1 or 0?
Run Code Online (Sandbox Code Playgroud)

Java的

set<A> aset;
A a = new A(1, 2); // Assume A has only two elements, and this constructor sets them both
aset.add(a);
A a2 = new A(1, 2); // This would initialise a `A' object to the same values as `a', but a different object
aset.contains(a2); // Would this return true or false?
Run Code Online (Sandbox Code Playgroud)

Bo *_*son 7

在C++中,集合依赖于为类A定义的operator <(),或者您提供了对集合提供严格弱排序的比较对象.