Daiki Ueno <[email protected]>: 
> I'm not familiar with C++, but is 'tmp' really needed here?
> 
>     autosprintf& operator = (autosprintf& src)

First of all, const correctness.
This would be fine with a move reference (C+11) autosprintf&& src, but a
copy constructor must not modify the copied object.

>     {
>       std::swap (str, src.str);

Think what happens when this is called from this line (a and b are
autosprintf objects):
a = b;
This call would swap the strings a.str and b.str, but it is not the
desired behavior, you want to free a.str and copy b.str into a.str.

The this pointer check is not needed with this copy pattern (copy
constructor and swap), but it optimizes out the useless copy at:
a = a;

Best regards,
Miguel



Reply via email to