Set
Probably Needs operator =()
Set
s and adding some elements
to a few of them.
We want to make things vaguely interesting, so we elect
to make the sets a little different to start with. The default constructor
should make all three Set
s empty at first ({}
) but
soon A should be {0,1,2,3,4}
and B should be
{2,3,4,5,6}
since B just adds the same number of elements as A,
but it adds two to each one before adding it.
At this point, we move onto the next code fragment...
Set
class. Rather than remove elements
by hand (how menial), we decide to just make A a copy of B, as below.
Equality works.
So we decide to make sure both cases for equality testing work (that it returns true when they are equal and false otherwise) so we opt to take 4 out of A and retest. Everybody watching?
Uh oh.
gets
printed to the screen. It almost undoubtedly does. Who knows why?
Take a minute and think about it. No rush. Actually, take the evening. I'll post the answer tomorrow.
Here's a hint: In C++, if you don't provide an assignment operator, the language provides one for you. The default assignment operator works as follows. If we're assigning A = B: