Operator Overloading

Hi...
I got this assignment on operator overloading, and i am new to this topic too. My
lecture said it is easy but i am new so it is not for me.

So when i done with my code, the complier gives me some error on a particular
operator that is the multiplication (*). Definitely there is something wrong with my
code on the function which i overload this operator, so i hope all the pros here can
help me figure it out? Million of thanks in advance~!

i will throw this in my compiler and see what shakes out, but right off the bat, there is a computational error in operator*, aside from any compilation errors - you're not multiplying a*b; you're multiplying default*b.

There are computational errors in every operator... almost.
The thing is that we want to, say, multiply something to with the current object and return the result. So obviously we cannot modify the original object (op1), so we need a temp. But that temp needs the values stored in op1, so you have to initialize it with *this.
myVector temp(*this);

Then you can proceed as usual.

As for the error, what you do is multiply an integer with a myVector, so the compiler looks for a operator * (int, myVector), which does not exist. Your overloaded member operator * is a operator * (myVector, myVector), which is not right. You need to use operators in the global namespace, which is easy, but I do not know if you have learned this yet. If not, then I would just put the integer on the right side of the multiplication and overload an operator * (int).

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.