digitalmars.D - No Access to lvalue in static operator overloads.
- Giles Bathgate (37/37) Jul 03 2007 In a previous post I was complaining that I could not access the lvalue ...
- Derek Parnell (8/29) Jul 03 2007 (maybe Test.oAddAssign(a,b); ?)
- Giles Bathgate (3/4) Jul 04 2007 I don't see whay it should be any different from existing operator overl...
- Frits van Bommel (5/13) Jul 04 2007 I he just meant to say that opAddAssign (as opposed to opCatAssign)
- Giles Bathgate (1/4) Jul 04 2007 Well sptted, I he just ment that teh
- Frits van Bommel (2/7) Jul 04 2007
- Giles Bathgate (2/3) Jul 05 2007 ^ yes can we stop teh silly thread now?
In a previous post I was complaining that I could not access the lvalue in a
static operator overload. I think the reason I was thinking this is because In
parameters lvalue and rvalue, the lvalue must be of the same type as the
contating type.
public class Test
{
public string Name;
public static Test operator +(Test lvalue, Test rvalue)
{
if (lvalue == null) { lvalue = new Test(); lvalue.Name = "foo";
}
if (rvalue == null) { rvalue = new Test(); rvalue.Name = "bar";
}
Console.Write(lvalue.Name);
Console.Write(rvalue.Name);
return rvalue;
}
}
static void Main(string[] args)
{
Test T = null;
Test B = null;
T += B;
}
imeplementation of static operator overloads is not very usefull.
What I prepose is that if the programmer specifies the following code:
public class Test
{
public static Test opAddAssign(Test lvalue, Test rvalue)
{
//...
}
}
When the user writes:
Test a;
Test b;
a += b;
Should compile into:
Test.opCatAssign(a,b);
I have no problem with Non static operator overloads as the lvalue can be
accessed using the this keyword.
Jul 03 2007
On Tue, 03 Jul 2007 15:24:06 -0400, Giles Bathgate wrote:
What I prepose is that if the programmer specifies the following code:
public class Test
{
public static Test opAddAssign(Test lvalue, Test rvalue)
{
//...
}
}
When the user writes:
Test a;
Test b;
a += b;
Should compile into:
Test.opCatAssign(a,b);
(maybe Test.oAddAssign(a,b); ?)
But I like the idea very much. It would solve, in a simple manner, some
issues I have.
--
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
Jul 03 2007
(maybe Test.oAddAssign(a,b); ?)I don't see whay it should be any different from existing operator overloads: http://www.digitalmars.com/d/operatoroverloading.html unless you mean that because its a "special" static overload that it should have a different name to existing static operator overloads? In that case you can tell the difference from the method signature, (so its like an overload overload if you know what I mean)
Jul 04 2007
Giles Bathgate snipped:Giles Bathgate wrote:a += b;Should compile into: Test.opCatAssign(a,b);I he just meant to say that opAddAssign (as opposed to opCatAssign) would be the correct method for "+=", but then made a typo and missed the 'p'...(maybe Test.oAddAssign(a,b); ?)I don't see whay it should be any different from existing operator overloads: http://www.digitalmars.com/d/operatoroverloading.html
Jul 04 2007
I he just meant to say that opAddAssign (as opposed to opCatAssign) would be the correct method for "+=", but then made a typo and missed the 'p'...Well sptted, I he just ment that teh
Jul 04 2007
Giles Bathgate wrote:^ There should be a "think" after that "I" :(...I he just meant to say that opAddAssign (as opposed to opCatAssign)would be the correct method for "+=", but then made a typo and missed the 'p'...Well sptted, I he just ment that teh
Jul 04 2007
^ yes can we stop teh silly thread now? I am teh l33t!Well sptted, I he just ment that teh
Jul 05 2007








Giles Bathgate <gilesbathgate gmail.com>