- Comparing two instances of the same class works as expected, obviously.
- Comparing an instance of a superclass against an instance of a subclass works, comparing the superclass properties only.
- Comparing an instance of a superclass to a pointer to a superclass instance works.
- Comparing two pointers containing two instances of exactly the same class works.
- Comparing an instance of the superclass against a pointer to a subclass instance does not work: division by zero error.
- Comparing two pointers containing one superclass instance and one subclass instance does not work: division by zero error.
- Comparing two pointers to superclass but containing two subclass instances works but this time comparing both the superclass and the subclass properties. This is not an error but it is interesting that it would behave different than the second case in this list.
- Comparing two pointers to the same subclass work normally.
- Did not test comparing instances of different subclasses or pointers to them.
Code: Select all
class A {
int an_int;
public A(int val) {
an_int = val;
}
};
class B : A {
int another_int;
public B(int val1, int val2) : A(val1) {
another_int = val2;
}
};
main () {
A a = new A(1);
A b = new B(1, 2);
DebugN(a == b);
shared_ptr<A> p_a = new A(1);
shared_ptr<A> p_b = new B(1, 2);
shared_ptr<A> p_c = new B(1, 3);
DebugN(a == p_a);
DebugN(a == p_b);
DebugN(p_a == p_b);
DebugN(p_b == p_c);
}
Daniel