V
Vladimir Jovic
Hello,
Reading 16.22 in c++ faq, I wondered why the assign operator wasn't
implemented like this :
FredPtr& operator= (FredPtr const& p)
{
FredPtr tmp( p );
std::swap( tmp, *this );
return *this;
}
The effect should be the same. tmp goes out of scope, and old object is
destroyed (count is decreated, and old object deleted if count=0), and
new object is copy constructed, therefore the count is increased by 1.
Is this correct, or am I missing something?
Reading 16.22 in c++ faq, I wondered why the assign operator wasn't
implemented like this :
FredPtr& operator= (FredPtr const& p)
{
FredPtr tmp( p );
std::swap( tmp, *this );
return *this;
}
The effect should be the same. tmp goes out of scope, and old object is
destroyed (count is decreated, and old object deleted if count=0), and
new object is copy constructed, therefore the count is increased by 1.
Is this correct, or am I missing something?