集如何区分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)
| 归档时间: |
|
| 查看次数: |
264 次 |
| 最近记录: |