Q) Operator
Overlaoded I have declared the "friend"
function into my component class (e.g. CPU), such as the below: class computer;
class CPU { friend computer& operator+=
(const computer&); public: ...
private: ... } But it gives me this error:
d:\concordia\2nd semester\comp5421\assignment2\sourcecode_part2\cpu.h(13)
: error C2805: binary 'operator +=' has too few parameters computer.cpp
d:\concordia\2nd semester\comp5421\assignment2\sourcecode_part2\cpu.h(13)
: error C2805: binary 'operator +=' has too few parameters Error executing
cl.exe. A) If
you declare/define the overloaded operator inside the class, then you need only
one (Computer) parameter since the left-hand one will be the current object. Since
you declared/defined the operator outside the class (similar to a free function),
the operator needs two (Computer) parameters. That is why this error is returned.
In short, you will need to have two parameters since the overloaded operator
is not a member of the class. |