- 论坛徽章:
- 0
|
写了子类coffee,它是继承base代码如下:
base.pm
package Bean;
use strict;
sub new {
my $type =shift;
my $this ={};
$this->{'Bean'} ='Colombian';
bless $this,$type;
return $this;
}
1; |
coffee.pm
package Coffee;
#use strict;
use base Bean;
sub printType{
my ($self,$name)=@_;
print "The type of Coffee is $self->{'Coffee'}\n";
}
sub new{
my $type =shift;
my $this =Bean->new();
$this->{'Coffee'} = klsdjk;
bless $this,$type;
return $this;
}
1; |
coffee.pm 放开 use strict; 编辑就报告my $this =Bean->new();错误,去除编译运行都OK。请大家指点,谢谢!
Bareword "Bean" not allowed while "strict subs" in use at Coffee.pm line 4.
Compilation failed in require at ./test.pl line 3.
BEGIN failed--compilation aborted at ./test.pl line 3.
[ 本帖最后由 sundycindy 于 2007-8-23 19:31 编辑 ] |
|