hi
I can't seem to figure out how to properly implement inheritance. I have one base class that I would like a variety of other classes to inherit from - but every time I try to code this (following my books or internet examples) I run into problems. I have the base class defined in one module (base.pm), and the children-to-be in others (say, child.pm). These children are then instantiated in another Perl program.
examples:
I first tried to access "bprint" from within the child module itself, and then moved it out to the main.p when that didn't work. I thought that the @ISA array would be searched for a package containing a method not defined in the current package, and hence "bprint" would be found? It doesn't seem to recognize that what's in base.pm is a package - I can do whatever I want to that code and not affect the erroneous outcome.
hmmmm, any help greatly appreciated (i've done lots of experimenting, to no avail..)
![[sad] [sad] [sad]](/data/assets/smilies/sad.gif)
dora c
I can't seem to figure out how to properly implement inheritance. I have one base class that I would like a variety of other classes to inherit from - but every time I try to code this (following my books or internet examples) I run into problems. I have the base class defined in one module (base.pm), and the children-to-be in others (say, child.pm). These children are then instantiated in another Perl program.
examples:
Code:
#***in file base.pm
package base
sub new
{
#-- new code here
}
sub bprint()
{
#-- some print code here
}
#***in file child.pm
package child
use base;
@ISA = qw(base); #so we're a base, and those methods should be
#available to instances of child
sub new
{
#-- new code here
}
sub print
{
#-- some other code here
}
#***in file main.p
use child;
$var = new child; #so far, so good
$var->print(); #still ok
$var->bprint(); #not ok, I get an error stating:
"can't locate object method "bprint" via package "child"
I first tried to access "bprint" from within the child module itself, and then moved it out to the main.p when that didn't work. I thought that the @ISA array would be searched for a package containing a method not defined in the current package, and hence "bprint" would be found? It doesn't seem to recognize that what's in base.pm is a package - I can do whatever I want to that code and not affect the erroneous outcome.
hmmmm, any help greatly appreciated (i've done lots of experimenting, to no avail..)
![[sad] [sad] [sad]](/data/assets/smilies/sad.gif)
dora c