On 11/6/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote:


Muttley Meen wrote:
> Hi!

Hello,

> $a = Package1::new();
> $a->Package2->Create(); # this should call IncErr too
> print "ERR1: $a->{err}\n"; # should print 1
> doent't work as I expected.
>
> Is there something wrong with the way I `bless`-ed the class Package2 ?

use strict, warnings, and most important: use base

And don;t use $a or $b as variable names, oi :)

Damian Conway's "Perl Best Practice" will make your life much easier!

I thought that $a might've been the cause :P

Anyway, I come to see my flaw, which was the misconception of inheritance.
I thought if B is inherited from A, and A was instantiated, then the Bs members
will refer to the same memory locations as As members, which is wrong.
I could deal with this by passing a parameter to the child constructor, pointing
to the parent $this reference.

Mumia, use Class::Struct uses the same trick of defining an array of methods,
similar to my $this->{r} used in the attached test.pl. Actually Class::Struct
generates perl code in a variable, and then evaluates it.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to