How can I make inheritance work with Bit::Vector? If inheritance won't work, what approach should I use?
The error message I get is 'Modification of a read-only value attempted' when I try to re-bless the Bit::Vector. If I don't re-bless, I get a Bit::Vector where I expect an LFSR object.
Here is my attempt so far:
The stripped-down calling program:
The stripped-down module:use strict; use warnings; use diagnostics; use LFSR; my $nbits = 127; my $t = new LFSR($nbits); # Inherited constructor print ref($t),"\n"; # Shows it is a Bit::Vector, not an LFSR # More proof that $t is a Bit::Vector print $t->isa('Bit::Vector'),"\n"; print $t->isa('LFSR'),"\n"; # This line: # bless $t, "LFSR"; # Causes this error: # 'Modification of a read-only value attempted'
I am running perl version 5.6.1.package LFSR; use strict; use warnings; use diagnostics; use Bit::Vector; our @ISA = qw(Bit::Vector); # This also causes an error at the bless statement, # so I have it commented out. =pod sub new { my ($class, $nbits)= @_; my $self= new Bit::Vector($nbits); bless $self, $class; return $self; } =cut sub mine { my $self= shift; my $class= ref($self) || $self; print "Hello\n"; } 1;
Thanks!
-toma
It should work perfectly the first time! - toma
In reply to How can I inherit from Bit::Vector? by toma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |