Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
June 09, 2005 0.126: New Struct Error | ||||
---|---|---|---|---|
| ||||
The code (much reduced from original): # module test; # # struct Entry # { # Entry* create() # { # Entry* theEntry = new Entry; # return theEntry; # } # } # # class Container # { # void add() # { # Entry* add = Entry.create(); # // .... # } # } Produces this error message (courtesy of dmd 0.126 on linux): test.d(16): this for create needs to be type Entry not type test.Container Can anybody decipher that message? That's verbatum! I'm not sure why it's not working either. This compiled on previous versions. -JJR |
June 09, 2005 Re: 0.126: New Struct Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Reimer | On Thu, 09 Jun 2005 04:55:25 -0700, John Reimer <brk_6502@yahoo.com> wrote:
> # module test;
> #
> # struct Entry
> # {
> # Entry* create()
> # {
> # Entry* theEntry = new Entry;
> # return theEntry;
> # }
> # }
> #
> # class Container
> # {
> # void add()
> #{
> # Entry* add = Entry.create();
> # // ....
> # }
> # }
Adding 'static' to create seems to fix it. eg. "static Entry* create()" etc.
Regan
|
June 09, 2005 Re: 0.126: New Struct Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Reimer | > The code (much reduced from original): > > # module test; > # > # struct Entry > # { Insert a "static" here. > # Entry* create() > # { > # Entry* theEntry = new Entry; > # return theEntry; > # } > # } > # > # class Container > # { > # void add() > # { > # Entry* add = Entry.create(); > # // .... > # } > # } Ciao uwe |
June 09, 2005 Re: 0.126: New Struct Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | Regan Heath wrote:
>
> Adding 'static' to create seems to fix it. eg. "static Entry* create()" etc.
>
> Regan
Thanks. I'm curious to know why this changes in the recent version.
-JJR
|
June 09, 2005 Re: 0.126: New Struct Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Reimer | In article <d8a3e5$23gj$1@digitaldaemon.com>, John Reimer says... > >Regan Heath wrote: >> >> Adding 'static' to create seems to fix it. eg. "static Entry* create()" etc. > >Thanks. I'm curious to know why this changes in the recent version. The error message stinks, but you should not be able to call a nonstatic method on a type unless it's through an instance of that type. I'm surprised that code ever worked. Sean |
June 09, 2005 Re: 0.126: New Struct Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Sean Kelly wrote:
> In article <d8a3e5$23gj$1@digitaldaemon.com>, John Reimer says...
>
>>Regan Heath wrote:
>>
>>>Adding 'static' to create seems to fix it. eg. "static Entry* create()" etc.
>>
>>Thanks. I'm curious to know why this changes in the recent version.
>
>
> The error message stinks, but you should not be able to call a nonstatic method
> on a type unless it's through an instance of that type. I'm surprised that
> code ever worked.
>
>
> Sean
>
>
Thanks. That makes sense. I was wondering if structs had an implicit static attribute on there methods in past versions. I haven't used structs much. With classes, I can see the necessity of using static.
-JJR
|
June 14, 2005 Re: 0.126: New Struct Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Reimer | "John Reimer" <brk_6502@yahoo.com> wrote in message news:d8a3e5$23gj$1@digitaldaemon.com... > Regan Heath wrote: > > > > Adding 'static' to create seems to fix it. eg. "static Entry* create()" > > etc. > > > > Regan > > Thanks. I'm curious to know why this changes in the recent version. Because it now checks for that particular mistake. Before, it would pass the wrong 'this' pointer to Entry.create(). |
June 14, 2005 Re: 0.126: New Struct Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Reimer | "John Reimer" <brk_6502@yahoo.com> wrote in message news:d8a5pn$25s9$1@digitaldaemon.com... > Thanks. That makes sense. I was wondering if structs had an implicit static attribute on there methods in past versions. No. You'd just get passed the wrong 'this'. If you accessed a member, a mess would happen. |
Copyright © 1999-2021 by the D Language Foundation