How to const-overload opEquals(R)(R rhs)?
Tobias Pankrath
tobias at pankrath.net
Tue Aug 7 06:40:18 PDT 2012
Hey,
let's say I have a simple struct and I want to give it an
opEquals like this.
struct Point
{
int x, y;
bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; }
}
With this I can't call opEquals on const instances of Point,
because dmd says
> bug.d(13): Error: function bug.Point.opEquals!(Point).opEquals
> (Point rhs) is not callable using argument types (Point) const
So I overoad is with a const version of oqEquals:
struct Point
{
int x, y;
bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; }
bool opEquals(R)(R rhs) const { return x == rhs.x && y ==
rhs.y; }
}
But the error stays the same. So why is the const version not
taken into consideration?
Thanks for your answers.
More information about the Digitalmars-d-learn
mailing list