Ring Ring - 3 months ago 11
C++ Question

How do you call the copy constructor within a member function of a class?

Here's what I've got:

void set::operator =(const set& source)
{
if (&source == this)
return;

clear();

set(source);
}


And here's the error I get:


vset.cxx:33: error: declaration of 'source' shadows a parameter


How do I properly do this?

Answer

I believe with set(source); you are trying to call copy ctor. You can not do that in C++ i.e. you can not explicitly invoke the ctor. What you can do is write a private clone method and call it in both copy ctor and assignment operator.