Multiextending

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Multiextending

Post 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
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

+1 :)
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

What happens when both cBase and tLayer have a structure field with the same name?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post 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:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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
Post Reply