opEquals does not work?

Namespace rswhite4 at googlemail.com
Fri Jun 7 13:43:27 PDT 2013


Did I miss something?

I expected this output
----
opEquals: 23 == 23
Equal 1
opEquals: 23 == 23
Equal 2
----
by the following code, but I only get this:
----
opEquals: 23 == 23
Equal 2
----

Code:
[code]
import std.stdio;

class A {
public:
	int id;

	this(int id) {
		this.id = id;
	}

	bool opEquals(const A a) const {
		writefln("opEquals: %d == %d", this.id, a.id);
		return a.id == this.id;
	}
}

void main() {
	A a1 = new A(23);
	A a2 = new A(23);

	if (a1 == a2) {
		writeln("Equal 1");
	}

	if (a1.opEquals(a2)) {
		writeln("Equal 2");
	}
}
[/code]


More information about the Digitalmars-d-learn mailing list