michaelg has asked for the wisdom of the Perl Monks concerning the following question:
OK, I started the Manager pack with "our @ISA = "Worker" but I couldn't do any thing for Bob there, When I wrote "use base ("Worker")" I was able to initiate Bob but I could't activate the wc method. So Bob need to go out with the common people. Thanks guysmy $jhon = Worker->new_worker(); $jhon->print_worker_data(); my $telma = Worker->new_worker(name => "Telama", age => 25); $telma->print_worker_data(); my $bob = Manager->new_worker(name => "Bob", age => 40); $bob->print_worker_data(); $bob->wc(); ##===================================== package Worker; sub new_worker { ## Constructor. my $invocant = shift; my $class = ref($invocant); my $self = { name => "Jhon Do", age => 32, @_ , }; bless ($self) ; return $self ; }; sub print_worker_data { my $self = shift; print $self->{name} . " age is:". $self->{age}."\n"; }; ##=========================================== package Manager; use base ("Worker"); sub wc{ my $self = shift; print $self->{name} . " is in title to use the managers toilet\n"; + };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inheritance problems
by Corion (Patriarch) on Aug 16, 2004 at 12:44 UTC | |
|
Re: inheritance problems
by dragonchild (Archbishop) on Aug 16, 2004 at 12:46 UTC | |
|
Re: inheritance problems
by Joost (Canon) on Aug 16, 2004 at 12:45 UTC | |
|
Re: inheritance problems
by ccn (Vicar) on Aug 16, 2004 at 12:39 UTC |