[Chicago-talk] Inheritance

petemar1 petemar1 at perlmonk.org
Sat Jan 10 14:19:19 CST 2004


...and I needed a "1;" at the end of BaseClass.pm

...and I needed to change a line in DerivedClass.pl from

    use lib qw( /home/petemar1/my_code/my_perl/ooperl/ooptest/BaseClass );

to

    use BaseClass

.

-----Original Message-----
From: chicago-talk-bounces at mail.pm.org
[mailto:chicago-talk-bounces at mail.pm.org]On Behalf Of Don Drake
Sent: Saturday, January 10, 2004 1:42 PM
To: 'Chicago.pm chatter'
Subject: RE: [Chicago-talk] Inheritance


This is not an inheritance problem, rather you have "use strict;" in your
code and you
don't declare $theDoer with my.

Change the line to this:
my  $theDoer = BaseClass->new();

And you're in business!

-Don

-----Original Message-----
From: chicago-talk-bounces at mail.pm.org
[mailto:chicago-talk-bounces at mail.pm.org]On Behalf Of petemar1
Sent: Saturday, January 10, 2004 1:35 PM
To: Chicago.pm chatter
Subject: [Chicago-talk] Inheritance


Given the following 2 separate files:


#!/usr/local/bin/perl -w
# BaseClass.pm

package BaseClass;

require BaseClass;

use strict;
use warnings;

{

    sub new {
        # my ($classname, @args) = @_;

        # my ($classname, @args) = shift;

        my $classname = shift;

        my $self = bless{}, $classname;

        return $self;
    }

    sub doTheThing() {
        print"\n yes \n";
    }
}



#!/usr/local/bin/perl -w
# DerivedClass.pl

package DerivedClass;

use strict;
use warnings;
# use base qw( BaseClass );
use lib qw( /home/petemar1/my_code/my_perl/ooperl/ooptest/BaseClass );

@MyApp::ISA = qw( BaseClass );
{

    $theDoer = BaseClass->new();

    # $theDoer = new BaseClass;

    # $theDoer->doTheThing();
}



What does the following error mean?

% perl DerivedClass.pl
Global symbol "$theDoer" requires explicit package name at DerivedClass.pl
line 14.
Execution of DerivedClass.pl aborted due to compilation errors.

_______________________________________________
Chicago-talk mailing list
Chicago-talk at mail.pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk

_______________________________________________
Chicago-talk mailing list
Chicago-talk at mail.pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk



More information about the Chicago-talk mailing list