Ring Ring - 1 year ago 59
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)



And here's the error I get:

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

How do I properly do this?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download