Hello,
I created two classes, class1 and class2. In a method (m1) of class 1 I
instanciate an object of class2 and want to access a method (m2) of this
class (class2), But I always get an error that the object method (m2)
cannot be located via package class2:
Can't locate object method "new" via package "class2" at class1.pm line 16.
What I am doing wrong?
Thanx in advance,
Matthias
Here is the example code:
./class1.pm:
-------
package class1;
use class1::class2;
use strict;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{TABLE} = [];
bless($self,$class);
return $self;
}
sub m1 {
my $self = shift;
my $ref=class2->new();
push(@{$self->{TABLE}},$ref);
$ref->m2();
}
1;
./class1/class2.pm:
------------
package class1::class2;
use strict;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{GREETING} = "Hi folks.";
bless($self,$class);
return $self;
}
sub m2 {
my $self = shift;
printf "\n%s\n", $self->{GREETING};
}
1;
./test.pl:
----
#!/usr/bin/perl -w -I.
use class1;
use strict;
my $ref=class1->new();
$ref->m1();
exit 0;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]