U
Unknown Poster
The behavior I'm seeing in Perl 5.6 contradicts what I understand
about copy constructors - specifically, when they are autogenerated.
# $f is a reference to an object
my $g = $f;
print "\$g = $g, ";
++$g;
print "after ++, \$g = $g, \$f = $f\n"; # The value of $g changes,
but the
# value of $f does not!
There is no overloading of "=" - no explicit copy constructor in the
class.
There is also no overloading of "++" in the class, but it is
apparently
autogenerated from the overloading of "+".
This appears to conflict with information in "The Copy Constructor"
section
of Programming Perl, 3rd edition.
Without a copy constructor, it states that the following would happen:
"$copy = $original; # copies only the reference
++$copy; # changes underlying shared reference"
"If the copy constructor is required during the execution of some
mutator,
but a handler for = was not specified, it can be autogenerated as a
string
copy provided the object is a plain scalar and notsomething fancier."
There are two separate scalar values in every object of the class,
so I don't see why the copy constructor is apparently being
autogenerated
in this case.
about copy constructors - specifically, when they are autogenerated.
# $f is a reference to an object
my $g = $f;
print "\$g = $g, ";
++$g;
print "after ++, \$g = $g, \$f = $f\n"; # The value of $g changes,
but the
# value of $f does not!
There is no overloading of "=" - no explicit copy constructor in the
class.
There is also no overloading of "++" in the class, but it is
apparently
autogenerated from the overloading of "+".
This appears to conflict with information in "The Copy Constructor"
section
of Programming Perl, 3rd edition.
Without a copy constructor, it states that the following would happen:
"$copy = $original; # copies only the reference
++$copy; # changes underlying shared reference"
"If the copy constructor is required during the execution of some
mutator,
but a handler for = was not specified, it can be autogenerated as a
string
copy provided the object is a plain scalar and notsomething fancier."
There are two separate scalar values in every object of the class,
so I don't see why the copy constructor is apparently being
autogenerated
in this case.