Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to make 'objFood' inherit from 'Object', but it doesn't seem to want to. @ISA doesn't want to do anything. Here are the packages in question:
#----------------------------------------------- package Object; #----------------------------------------------- sub create { my ($pkg, $name, $weight) = @_; my $obj = bless { "name" => $name, "weight" => $weight, "created" => time, }, $pkg; return $obj; } #----------------------------------------------- package objFood; #----------------------------------------------- @objFood::ISA = qw(Object); sub new { my ($pkg, $name, $weight, $size, $life) = @_; my $obj = $pkg->create($name, $weight); $obj->{"size"} = $size; $obj->{"life"} = $life; return $obj; }
To call it I use, for example:
my $obj1 = objFood->new('cheese', 1, 3, 600);
The error message I get is:
Can't locate object method "create" via package "objFood" (perhaps you forgot to load "objFood"?) at ./nat line 141.
Any thoughts?
Thanks in advance,
--
Dave.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: Inheritance not working...
by jeffa (Bishop) on Mar 08, 2003 at 13:39 UTC | |
|
Re: Inheritance not working...
by adrianh (Chancellor) on Mar 08, 2003 at 13:45 UTC | |
|
Re: Inheritance not working...
by hv (Prior) on Mar 08, 2003 at 16:53 UTC | |
|
Re: Inheritance not working...
by bart (Canon) on Mar 09, 2003 at 12:21 UTC |