[Gambas-user] INHERITS, name resolution

Christian Faure christian.faurebouvard at ...357...
Thu Jun 24 20:24:31 CEST 2004


Hi All,
Before all, The Gambas is VERY GOOD, thanks.

I have a small test for objet inheritance based on 2 classes:

--------BEGIN FILE Class1-------------
' Gambas class file
PRIVATE d1 AS String 

PUBLIC SUB m1()
  PRINT "C1::m1 " 
END
-------- END FILE Class1-------------
--------BEGIN FILE Class2-------------
' Gambas class file
INHERITS Class1
PRIVATE d2 AS String 

PUBLIC SUB m2()
  PRINT "C2::m2 " 
END
-------- END FILE Class2-------------
-------- In a form  i have a button1---
PUBLIC SUB Button1_Click()
  DIM c AS Object
  c=NEW class2
  c.m1()
END
------- END source code -----------

The Problem:
when click the button
i expect in console "C1::m1" 

but, i see "C2::m2" 
:-(

It is a bug ?

I have two workaround's
workaround 1:
-------- In a form  i have a button1---
PUBLIC SUB Button1_Click()
  DIM c AS Object
  dim d as Class1
  c=NEW class2
  d=c ' d and c references the same object, but d as declared as Class1
  d.m1()
END
------- end source ----
workaround 2:
In the class2 use a "ancestor" variable and re-declare method m1 to call 
ancestor.m1()
--------BEGIN FILE Class2-------------
' Gambas class file
INHERITS Class1
PRIVATE d2 AS String 

PUBLIC SUB m1()
  dim ancestor as Class1
  ancestor=me
  ancestor.m1()
END

PUBLIC SUB m2()
  PRINT "C2::m2 " 
END
-------- END FILE Class2-------------

i think it is a small bug :->, i are interesting to solve it, 
Can help me to find the algorithm of name resolution
of methods in gambas source code? 

Thanks.





More information about the User mailing list