Guys, can u plz help me out. Why is following error coming twice in the folowing program? error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class counter' (or there is no acceptable conversion)
I think it more to do with this particular statement. c2 = ++c1;
Now both c2 and c1 are of class countDn
when the compiler does operation ++c1, the ++ (pre-increment) operator of the counter base class is called, because the countDn class does not provide a ++ operator of it's own.
We note that the counter class ++ function counter operator++() returns a counter
object.
So this statement c2 = ++c1 will end up trying to assign a counter object to a countDn object.
As we have NOT made an assignment operator function in the countDn class to allow
for this to happen - then we get the error reported by the compiler.
The same thing applies to this c2 = c1++; statement