www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - 0.126: New Struct Error

reply John Reimer <brk_6502 yahoo.com> writes:
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
Jun 09 2005
next sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
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
Jun 09 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
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
Jun 09 2005
next sibling parent reply Sean Kelly <sean f4.ca> writes:
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
Jun 09 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
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
Jun 09 2005
parent "Walter" <newshound digitalmars.com> writes:
"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.
Jun 14 2005
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"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().
Jun 14 2005
prev sibling parent "Uwe Salomon" <post uwesalomon.de> writes:
 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
Jun 09 2005