Thread Unerwartetes Verhalten bei Operator überladen (10 answers)
Opened by Muffi at 2012-08-21 17:05

Gast Gast PB
 2012-08-22 11:29
#161250 #161250
Hallo.

Zitat aus perldoc overload Abschnitt Copy Constructor:

Quote
If 'fallback' is undefined or TRUE then a copy constructor can be autogenerated, but only for objects based on scalars. In other cases it needs to be defined explicitly. Where an object's data is stored as, for example, an array of scalars, the following might be appropriate:

use overload '=' => sub { bless [ @{$_[0]} ] }, # ...


und

Quote
If 'fallback' is TRUE and no copy constructor is defined then, for objects not based on scalars, Perl may silently fall back on simple assignment - that is, assignment of the object reference. In effect, this disables the copy constructor mechanism since no new copy of the object data is created. This is almost certainly not what you want. (It is, however, consistent: for example, Perl's fallback for the "++" operator is to increment the reference itself.)


M.a.W. es fehlt höchstwahrscheinlich ein Copy-Konstruktor für Class::Date (basiert auf AREFs statt Scalar?).

HTH

View full thread Unerwartetes Verhalten bei Operator überladen