I read in a tutorial, something like that to call the constructor:
my $v = Vehicule->new( 2, "bleu" );
Then the concerned class is something like that
sub new {
my ($class,$nbRoues,$couleur) = @_;
my $this = {};
bless($this, $class);
$this->{NB_ROUES} = $nbRoues;
$this->{COULEUR} = $couleur;
return $this;
}
The thing I don't understand is how/why @_ first element contains the classname?
my ($class,$nbRoues,$couleur) = @_
when we call it like this Vehicule->new( 2, "bleu" );
Same for method/function of the class with something like that
my ($this) = @_ ;
Actually I don't really understand Class->new or $var->method
Vehicule->new(2, "bleu")asnew Vehicule 2 "bleu"akin to other perl subroutine calls. IOW,newis just a sub. Have a look at perlobj