The bottom line is that the derived class has to disambiguate access to base class members as required. Consider:
package Foo; my $pkg = __PACKAGE__; sub new { my $class = shift; return bless {$pkg => {basetype => $pkg}}, $class; } sub showBase { my $self = shift; print ref ($self) . ": $self->{$pkg}{basetype}\n"; } package Bar; my $pkg = __PACKAGE__; sub new { my $class = shift; return bless {$pkg => {basetype => $pkg}}, $class; } sub showBase { my $self = shift; print ref ($self) . ": $self->{$pkg}{basetype}\n"; } package Baz; use base qw(Foo Bar); sub new { my $class = shift; my $bar = Bar::new ($class); my $foo = Foo::new ($class); my %self; @self{keys %$foo} = values %$foo; @self{keys %$bar} = values %$bar; return bless \%self, $class; } package Boo; use base qw(Foo Bar); sub new { my $class = shift; my $bar = Bar::new ($class); my $foo = Foo::new ($class); my %self; @self{keys %$foo} = values %$foo; @self{keys %$bar} = values %$bar; return bless \%self, $class; } sub showBase { my $self = shift; Foo::showBase ($self); Bar::showBase ($self); } package main; my $baz = Baz->new (); my $boo = Boo->new (); print "Baz's showBase:\n"; $baz->showBase (); print "Boo's showBase:\n"; $boo->showBase ();
Prints:
Baz's showBase: Baz: Foo Boo's showBase: Boo: Foo Boo: Bar
In reply to Re: How to do multiple inheritance?
by GrandFather
in thread How to do multiple inheritance?
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |