小编Ome*_*evy的帖子

为什么$ class-> SUPER :: new在使用多重继承时不调用所有父类的构造函数?

我试图在Perl中使用多继承,但我无法弄清楚如何从子构造函数调用多个父构造函数.

A.pm:

package A;
use Carp qw (croak);
use strict;
use warnings;

sub new {
    my $class = shift;
    print "This is A new\n";
    my $self->{DEV_TYPE} = shift || "A";
    bless($self, $class);
    return $self;
}

sub a_func{
    print "This is A func\n";
}

1;
Run Code Online (Sandbox Code Playgroud)

B.pm:

package B;
use Carp qw (croak);
use strict;
use warnings;

sub new {
    my $class = shift;
    print "This is B new\n";
    my $self->{DEV_TYPE} = shift || "B";
    bless($self, $class);
    return $self;
}

sub b_func{ …
Run Code Online (Sandbox Code Playgroud)

perl multiple-inheritance

4
推荐指数
1
解决办法
643
查看次数

标签 统计

multiple-inheritance ×1

perl ×1