Bug 4174 – Template interface functions not allowed, making operator overloads difficult
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-05-10T14:35:00Z
Last change time
2012-04-27T19:33:15Z
Keywords
pull, rejects-valid
Assigned to
yebblies
Creator
schveiguy
Comments
Comment #0 by schveiguy — 2010-05-10T14:35:10Z
Comment #1 by schveiguy — 2010-05-10T14:41:26Z
Sorry, enter key added the issue when I was typing the summary.
Operator overloads require template functions, yet this doesn't work:
interface I
{
I addAssign(I other);
I opOpAssign(string op)(I other) if (op == "+=")
{
return this.addAssign(other);
}
}
void foo(I i)
{
i += i;
}
error message:
testinterface.d(4): Error: function testinterface.I.opOpAssign!("+=").opOpAssign template member functions are not allowed in interface I
testinterface.d(12): Error: template instance testinterface.I.opOpAssign!("+=") error instantiating
How shall I implement operators for interfaces?
Comment #2 by andrei — 2010-12-29T12:37:55Z
That should be op == "+". With that change I am getting the same error message. Assigning to Walter to expedite review.