[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Accessing in a child class the attribute of a parent class
- From: Luciano de Souza <luchyanus@...>
- Date: Wed, 05 Jan 2011 22:27:27 -0200
I really get angry with myself when the problem is the lack of
attention. Sometimes, reading rapidly with the screen reader, some
information were ignored by brain, especially because the hurry. Your
are right. the problem is the bad usage of classlib.
The correct code is:
require('classlib')
class.parent()
function parent:__init()
self.a = 15
end
class.child(shared(parent))
function child:__init()
parent:__init()
self.b = 22
end
function child:display()
print(parent.a)
print(self.b)
end
x = child()
x:display()
On 05-01-2011 21:43, Tomas Guisasola Gorham wrote: Hi Luciano
The line 08 should be replaced from "class.child()", a simple class,
to "class.child(parent)", subclass inheriting attributes and methods
of "parent".
But, despite this mistake, the problem related in the previous message
is still occuring with the same exact diagnosis!
I noticed the mistake and changed the code as you mentioned above.
Then I renamed the __init methods to __user_init, but in both versions
the problem still occurs. I can't understand why, but classlib is
calling child:__init (or __user_init) before calling parent:__init (or
__user_init). Worst, it is calling the functions with different values
of self, thus the attributes are initialized in different objects :-(
I think you have to study classlib to understand how it should
be used.
Regards,
Tomás