in reply to Error in Inheritance Class
creates an object of "ParantClass". In other words, you're only ever dealing with ParantClass objects, while you think you're dealing with Child1Class objects.my $self=ParantClass->new();
You should ALWAYS use the 2 argument form of bless() and use the first argument to the constructor (i.e. the expected classname) as the second argument:
# in the parent class: sub new { my ($class) = @_; my $self = bless { },$class; # ... return $self; } # in the child class: # if you really need to override the constructor # you can use this: sub new { my ($class) = @_; my $self = $class->SUPER::new(); # call parent constructor # .... return $self; }
|
|---|