opEquals the template?
Jonathan M Davis
jmdavisProg at gmx.com
Sat Oct 1 18:45:27 PDT 2011
On Sunday, October 02, 2011 03:39:29 Andrej Mitrovic wrote:
> Is opEquals not allowed to be a template in a struct? Because I was
> using it in my library, and it sort-of worked, up until it started
> causing some really weird bugs where a ctor was called instead of
> opCast. This results in an error code returned by the compiler:
>
> struct Foo
> {
> bool opEquals(T)(ref const T rhs) const
> {
> return this == this;
> }
> }
>
> void main()
> {
> auto foo = Foo();
> assert(foo == foo);
> }
>
> Exit code: -1073741819
>
> And yet it worked fine in a larger module until I've hit the random
> buggy behavior.. I don't understand..
Struct's are a completely different issue. opEquals for structs is not handled
the same way as it is for classes. Their biggest issue is
http://d.puremagic.com/issues/show_bug.cgi?id=3659 and that was finally fixed a
couple of days ago. There may be further bugs with it, but the issue that
Steven is bringing up is about classes, not structs.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list