I have a class SimpleCircle. Its declaration is as follows:
class SimpleCircle
{
public:
SimpleCircle();
SimpleCircle(int rad);
SimpleCircle(const SimpleCircle&);
~SimpleCircle();
SimpleCircle operator++(int);
}
On the definition I use:
SimpleCircle SimpleCircle::operator++(int)
{
SimpleCircle temp(*this);
++itsRadius;
return temp;
}
When I am using
SimpleCircle temp(*this)
, is the copy constructor being called or what ? What is happening there ? I don’t have any constructor like
SimpleCircle(SimpleCircle newCircle)
or something (other than the copy constructor)
This does indeed call the copy constructor. While you don’t have a
SimpleCircle(SimpleCircle other)constructor defined you do haveSimpleCircle(const SimpleCircle&)defined. The expression*thiscan easily map to that constructor and hence it’s what’s being executed here.