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.
In reply to Inheritance not working... by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |