PureBasic Forum
https://www.purebasic.fr/english/

Multiextending
https://www.purebasic.fr/english/viewtopic.php?f=3&t=32647
Page 1 of 1

Author:  Hroudtwolf [ Sat May 31, 2008 7:14 am ]
Post subject:  Multiextending

Hi,

I've a little wish again.
It would be very cool, if you could make it possible, that we can use more than one extends with structures.

In example:
Code:
Structure cLayer Extends cBase Extends tLayer
EndStructure


The constructing of datasets, based on propertyfragments would be very easy.

Best regards

Wolf

Author:  Mistrel [ Sat May 31, 2008 11:35 am ]
Post subject: 

+1 :)

Author:  eesau [ Sat May 31, 2008 11:46 am ]
Post subject: 

What happens when both cBase and tLayer have a structure field with the same name?

Author:  Mistrel [ Sat May 31, 2008 12:51 pm ]
Post subject: 

eesau wrote:
What happens when both cBase and tLayer have a structure field with the same name?


It would probably result in a compiler error. :roll:

Author:  Trond [ Sat May 31, 2008 6:35 pm ]
Post subject: 

That will destroy the whole concept of Extends, which is that the fields are placed first in the structure, so that the structure can be passed to functions expecting a pointer to the old structure.

This is how it works:
Code:
Structure SShape
  Color.l
EndStructure

Structure SRectangle Extends SShape
  Width.l
  Height.l
EndStructure

Procedure SShape_GetColor(*Shape.SShape)
  ProcedureReturn *Shape\Color
EndProcedure

My.SRectangle\Color = $deadbeef
Debug Hex(SShape_GetColor(@My))



Multi-extending is impossible, because the fields of SSoccerField and SShape can't both be placed first in SRectangle. That will make the code above mysteriously fail on this rectangle.
Code:
Structure SSoccerField
  NumberOfPlayers.l
EndStructure

Structure SShape
  Color.l
EndStructure

Structure SRectangle Extends SSoccerField Extends SShape
  Width.l
  Height.l
EndStructure

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/