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 ;
...全文
112 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wti 2005-03-21
  • 打赏
  • 举报
回复
qw(xx, yy);
qw 里面得东西不用逗号分割
在程序得开端加上
use warnings;
use strict;
可以减少很多得错误

my $class = @_;
不知道这里你要做什么,但是$class只会得到参数得个数
fibbery 2005-03-18
  • 打赏
  • 举报
回复
我正在研究类的继承.stamp

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧