- 論壇徽章:
- 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 放開(kāi) use strict; 編輯就報(bào)告my $this =Bean->new();錯(cuò)誤,去除編譯運(yùn)行都OK。請(qǐng)大家指點(diǎn),謝謝!
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 編輯 ] |
|