digitalmars.D - Need 'this' to access 'opCall'? Was I trying to?
- Mehrdad (10/10) Sep 26 2011 struct Adder {
- Trass3r (1/1) Sep 26 2011 Your opCall isn't static.
- Mehrdad (3/4) Sep 26 2011 Yeah, I don't want it to be. I want to use opCall on an instance, not on...
- Jonathan M Davis (6/11) Sep 26 2011 Well, it looks like having declared a non-static opCall makes the
- Regan Heath (19/31) Sep 26 2011 I couldn't get that to work.. but this does:
- Trass3r (2/5) Sep 26 2011 I do think it's a bug. Only a static opCall should interfere with the
- Mehrdad (2/7) Sep 26 2011 Yeah I agree -- should I file it as one?
- Steven Schveighoffer (5/13) Sep 26 2011 Might want to add this case (as I think it is important, and doesn't yet...
- Mehrdad (3/17) Sep 26 2011 Done!
struct Adder { int v; auto opCall(int x) { return x + v; } } auto adder(int v) { return Adder(v); // How do I call the constructor?? } int main() { auto a = adder(5); }
Sep 26 2011
On 9/26/2011 8:13 AM, Trass3r wrote:Your opCall isn't static.Yeah, I don't want it to be. I want to use opCall on an instance, not on the type.
Sep 26 2011
On Monday, September 26, 2011 09:01:20 Mehrdad wrote:On 9/26/2011 8:13 AM, Trass3r wrote:Well, it looks like having declared a non-static opCall makes the automatically generated constructor for the struct unusable - which may or may not be a bug (there are similar issues with declaring opCast). If you just declare a constructor, it should solve the problem. - Jonathan M DavisYour opCall isn't static.Yeah, I don't want it to be. I want to use opCall on an instance, not on the type.
Sep 26 2011
On Mon, 26 Sep 2011 17:14:45 +0100, Jonathan M Davis <jmdavisProg gmx.com> wrote:On Monday, September 26, 2011 09:01:20 Mehrdad wrote:I couldn't get that to work.. but this does: import std.stdio; struct Adder { int v; auto opCall(int x) { return x + v; } } auto adder(int v) { Adder a; a.v = v; return a; } void main() { auto a = adder(5); writefln("%s", a(5)); } -- Using Opera's revolutionary email client: http://www.opera.com/mail/On 9/26/2011 8:13 AM, Trass3r wrote:Well, it looks like having declared a non-static opCall makes the automatically generated constructor for the struct unusable - which may or may not be a bug (there are similar issues with declaring opCast). If you just declare a constructor, it should solve the problem.Your opCall isn't static.Yeah, I don't want it to be. I want to use opCall on an instance, not on the type.
Sep 26 2011
Well, it looks like having declared a non-static opCall makes the automatically generated constructor for the struct unusable - which may or may not be a bugI do think it's a bug. Only a static opCall should interfere with the constructor.
Sep 26 2011
On 9/26/2011 9:40 AM, Trass3r wrote:Yeah I agree -- should I file it as one?Well, it looks like having declared a non-static opCall makes the automatically generated constructor for the struct unusable - which may or may not be a bugI do think it's a bug. Only a static opCall should interfere with the constructor.
Sep 26 2011
On Mon, 26 Sep 2011 13:13:52 -0400, Mehrdad <wfunction hotmail.com> wrote:On 9/26/2011 9:40 AM, Trass3r wrote:Might want to add this case (as I think it is important, and doesn't yet seem to have an exact duplicate report) to bug 6036. Looks like Kenji is on the case, and he usually comes up with a pull request :) -SteveYeah I agree -- should I file it as one?Well, it looks like having declared a non-static opCall makes the automatically generated constructor for the struct unusable - which may or may not be a bugI do think it's a bug. Only a static opCall should interfere with the constructor.
Sep 26 2011
On 9/26/2011 10:34 AM, Steven Schveighoffer wrote:On Mon, 26 Sep 2011 13:13:52 -0400, Mehrdad <wfunction hotmail.com> wrote:Done! http://d.puremagic.com/issues/show_bug.cgi?id=6036On 9/26/2011 9:40 AM, Trass3r wrote:Might want to add this case (as I think it is important, and doesn't yet seem to have an exact duplicate report) to bug 6036. Looks like Kenji is on the case, and he usually comes up with a pull request :) -SteveYeah I agree -- should I file it as one?Well, it looks like having declared a non-static opCall makes the automatically generated constructor for the struct unusable - which may or may not be a bugI do think it's a bug. Only a static opCall should interfere with the constructor.
Sep 26 2011