Multiple extends
BlitzMax Forums/BlitzMax Programming/Multiple extends
| ||
Is it possible to create two types (if not, will it ever be included in BlitzMax?), lets say Type Point and Type Angle, then create the third type called Entity and extend both of those? It would create neat code but doesn't seem to possible :/. |
| ||
No this is not possible. BM only supports single inheritance. But what you can do is extend it from one and hold the other type as field and use both for example. Or doing meta inheritance using the reflection features. (I am thinking about a possibility of how to missuse that to give BM Interface capabilities like JAVA has them so you can extend from one class but implement different interfaces) |
| ||
Meta Inheritance. Cool ;-) I could really do with Interfaces... surely it can't be that hard to implement?? Mark! :-p |
| ||
Not really multiple inheritance, but I've used this before to share functions between types that are not related.Local myvar:Tmytype = New Tmytype Print myvar.Capital( "blitzmax" ) Print myvar.Length( "blitzmax" ) Print myvar.Reverse( "blitzmax" ) Type TParent Method Capital$( str$ ) Return Upper( str ) End Method End Type Type Tmytype Extends TParent '# Multiple inheritance Field reverse$(str$) = IInterface.Reverse '# Method Length$( str$ ) Return "Length: " + Len(str) End Method End Type Type Iinterface Function reverse$( str$ ) Local result$ For Local n% = Len(str) To 1 Step - 1 result:+ str[n-1..n] Next Return result End Function End Type |