perl中关于类的问题!请各位高人指点!
pjm02 2004-08-31 03:57:44 我定义了一个父类(Father)和一个子类(Child)。当实例化子类时。父类中的New方法能够实现。但是父类中的其他过程不能通过子类来实现,不知道到底是哪里出了错误。请高人指点!
父类:
package Father;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(fatherCopy,copy);
sub new {
my $type = shift;
my $this = {} ;
print " Father new() \n";
bless $this, $type;
return $this;
}
sub fatherCopy {
my $class=@_;
print " fatherCopy()\n";
}
sub copy {
my $class=@_;
print " copy() from father \n";
}
1;
子类:
package Child;
require Exporter;
require Father;
@ISA = qw(Exporter,Father);
@EXPORT = qw(childCopy, copy);
sub new{
my $type1 = shift;
my $this = Father->new();
print "Child new() \n";
bless $this,$type1;
return $this;
}
sub childCopy{
my $class = @_;
print "childCopy() \n";
}
sub copy{
my $class = @_;
print "Copy() called from Child \n";
}
1;
程序:
#! /usr/bin/perl
#push (@INC,"pwd");
use Child;
$c=new Child;
$c->childCopy;
$c->copy ;
$c->fatherCopy ;