Using Self and Super for Fields
BlitzMax Forums/BlitzMax Programming/Using Self and Super for Fields| 
 | ||
| Is it possible to use self and super for fields within extended types? | 
| 
 | ||
| What happens when you try? | 
| 
 | ||
| Type Base Field Test:String = "Base Field" End Type Type Extended Extends Base Field Test:String = "Extended Field" Method Debug() Print Super.Test Print Self.Test End Method End Type Local Example:Extended = New Extended Example.Debug() Gives an error "Identifier Test Not Found" at "Print Super.Test". I guess that's my answer. | 
| 
 | ||
| You need to typecast it: Print Base(Super).Test | 
| 
 | ||
| Which makes the use of Super pretty redundant as you might just as well use... Print Base(Self).Test Super *should* work with fields, should it not? | 
| 
 | ||
| Yeah I guess it should unless I'm missing something (like it would break inheritance or something).  It works with methods and functions of course: Type Base Field Test:String = "Base Field" Method GetTest$() Return test End Method Function Test2$() Return "Base Test2" End Function End Type Type Extended Extends Base Field Test:String = "Extended Field" Method GetTest$() Return test End Method Function Test2$() Return "Extended Test2" End Function Method Debug() Print Super.GetTest() Print Self.GetTest() Print Super.Test2() Print Self.Test2() End Method End Type Local Example:Extended = New Extended Example.Debug() |