Hi All,

following OO i have tried the following:
but i found that there is a diffence between:

#my $c1 = Number::Complex::new(2,5);
my $c1 = new Number::Complex(2,5);

Seems like I am getting a warning saying my number is not numeric ??!!
(what tring to run the 'add' sub)
Can any one explain it to me ?
thanks
Chanan

This is what i tried:
================
package Number::Complex;
sub new
{
    my ($real, $image) = @_;
        my $ref_c = { _real  => $real, _image => $image };
        bless $ref_c, "Number::Complex";
        return $ref_c;
}

sub toString
{
    my $ref_c = shift; return "$ref_c->{_real} + $ref_c->{_image}i";
}

sub add
{
   my ($ref_c1, $ref_c2) = @_;
   my $ref_c = Number::Complex::new($ref_c1->{_real} +
$ref_c2->{_real}, $ref_c1->{_image} + $ref_c2->{_image});
   return $ref_c;
}

#my $c1 = Number::Complex::new(2,5);
my $c1 = new Number::Complex(2,5);
my $c2 = Number::Complex::new(3,4);

my $c3 = $c1->add($c2);

-- 
===================
----     Chanan Berler    ----
===================
_______________________________________________
Perl mailing list
Perl@perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to