Types and polymorphism
BlitzMax Forums/BlitzMax Beginners Area/Types and polymorphism
| ||
After reading John Judnich's great tutorial on OOP and BlitzMax, I though i had finally got round my head round the subject. Alas, no, hence I'm appealing for help... I have a type, TEntity that is Extended by THuman. The field "somevalue" is set in TEntity. I have some very simple code: Local human:THuman=New THuman Local entity:TEntity entity=human Can someone explain why the values of human.somevalue and entity.somevalue are different? Thanks, a confused Welshman. |
| ||
Well, without seeing your code, I don't know if this is the problem or not, but I'm guessing that you are redefining somevalue in THuman. Try copying and pasting this and you'll see it works... Strict Type Entity Field SomeValue:Int Method New() SomeValue = 55 EndMethod EndType Type Human Extends Entity EndType Local Hum:Human = New Human Local ent:Entity ent = Hum Print "Ent.Somevalue = " + ent.somevalue Print "Hum.SomeValue = " + hum.somevalue However, if you change type human to the following, it won't work. Type Human Extends Entity field SomeValue:int EndType In this case, you've redefined SomeValue in type Human, and this redefined value is NOT set in the base class New() method. |
| ||
I think that is the problem. I thought I could "overload" the field, but obviously not. Thanks for your help! |