Re: Copy Constructor Craziness
From: Jay Tilton (tiltonj_at_erols.com)
Date: 02/09/04
- Next message: Agrapha: "Re: A Grep and a couple Awks <and a lot of Tassilo help>"
- Previous message: Ben Morrow: "Re: A Grep and a couple Awks <and a lot of Tassilo help>"
- In reply to: Unknown Poster: "Re: Copy Constructor Craziness"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 09 Feb 2004 06:02:16 GMT
use63net@yahoo.com (Unknown Poster) wrote:
: The next sentence is also verrrry interesting:
: "However, this does not trigger the copying behavior that a real
: ++ operator would."
:
: Horsefeathers! That is exactly what is happening in this case.
: A copy constructor is being autogenerated.
You are mistaken. There is no copy constructor involved at all.
: In the example earlier in the thread, "++" is not EXPLICITLY
: overloaded, but "+" is (and += is not). The copy constructor
: is being autogenerated in this case - it is self-evident in
: that $g and $f end up referencing different objects, while
: there was no overloading of "=".
If the overloaded '+' returns a new object, as it does in the pared-down
demonstration class I wrote in the previous article, how could you
sensibly expect an autogenerated '++' not to? This is not any kind of
evidence that a copy constructor is being used.
If your own overloaded '+' does not return a new object, it's time for
you to show the code for your overloaded operators.
: The text of Programming Perl 3E
: seems to be wrong, or at least very misleading,
The book is at least 3.5 years behind the Perl docs' revision state.
Save accusations of incorrectness for the current version.
Obsolescence issues aside, the fourth paragraph in the "The Copy
Constructor (=)" section of chapter 13 plainly says:
The need for copying is recognized only by mutators such as ++ or
+= . . . . If the operation is autogenerated via +, . . . then no
copying occurs, . . . .
What do you find wrong or misleading about that?
: because I don't see any justification for this autogeneration.
You're chasing phantoms here. There is no autogenerated copy
constructor.
: Now, for another intersesting result. When I do explicitly overload
: "++" in the class, Perl bombs out at "++g" with an error message stating:
: "... Operation '=', no method found, argument in overloaded
: package Rational ..."
Yes. If you're overloading a mutator, there needs to be a copy
constructor. If you're letting the mutator be autogenerated, a copy
constructor is irrelevant.
- Next message: Agrapha: "Re: A Grep and a couple Awks <and a lot of Tassilo help>"
- Previous message: Ben Morrow: "Re: A Grep and a couple Awks <and a lot of Tassilo help>"
- In reply to: Unknown Poster: "Re: Copy Constructor Craziness"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|