On Jun 2, Matthew Sacks said:
When you invoke a method, the first argument to the method equal to the method's invocant is automatically inserted.
That sounds about right. The first argument to a method is either a class name or the object, depending on whether it's a class method or an object method:
my $foo = SomeClass->new('blah'); The arguments to the 'new' method are ('SomeClass', 'blah'). $foo->some_method(10, 50); The arguments to the 'some_method' method are ($foo, 10, 50).
i) Is this essentially the same as a C++ "this" pointer?
Yes; the first argument to an object method is the object, which is synonymous to the 'this' pointer in C++.
ii) Apparently, the first argument can be a reference to its object, or the object.
Uh, that sounds wrong. Objects *are* references in Perl, just a special kind of reference. An object is a reference that has been "blessed" into a particular package/class/namespace:
package SomeClass; sub new { my $pkg = shift; # $pkg is the class to bless into... it is not # NECESSARILY SomeClass, because a class could # be inheriting its new() method from SomeClass my $obj = bless [EMAIL PROTECTED], $pkg; return $obj; } A reference to an object is not necessarily an object. That is: $foo->some_method(...); works, but my $ref_to_foo = \$foo; $ref_to_foo->some_method(...); does NOT work.
iii) There is an example in the Camel book, in the Object-Oriented-Programming Chapter (ch. 12), where accessor methods are being generated automatically; in this example, it seems that the invocant is explicity placed into the first argument. If you put in the this pointer, does PERL know not to put in another one?
I don't have my Camel at hand. Is this an AUTOLOADing issue? -- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ % -- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>