Page 1 of 1

Multiextending

Posted: Sat May 31, 2008 7:14 am
by Hroudtwolf
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: Select all

Structure cLayer Extends cBase Extends tLayer
EndStructure
The constructing of datasets, based on propertyfragments would be very easy.

Best regards

Wolf

Posted: Sat May 31, 2008 11:35 am
by Mistrel
+1 :)

Posted: Sat May 31, 2008 11:46 am
by eesau
What happens when both cBase and tLayer have a structure field with the same name?

Posted: Sat May 31, 2008 12:51 pm
by Mistrel
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:

Posted: Sat May 31, 2008 6:35 pm
by Trond
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: Select all

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: Select all

Structure SSoccerField
  NumberOfPlayers.l
EndStructure

Structure SShape
  Color.l
EndStructure

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