overload the *


B

billq

Hello,
I have the following function which overloads the * sign in order to
multiply a 3 axis vector by a scaler.

public static _3DVector operator * (_3DVector vec, float num)
{
_3DVector v = new _3DVector();
v.X = num * vec.X;
v.Y = num * vec.Y;
v.Z = num * vec.Z;

return v;
}

From the examples I am following this should work but, I get an error
when I try to build the solution which says

One of the parameters of a binary operator must be the containing type.

I do not understand what this means. Any help will be appreciated.
thanks
bill
 
Ad

Advertisements

M

Michael C

billq said:
Hello,
I have the following function which overloads the * sign in order to
multiply a 3 axis vector by a scaler.

public static _3DVector operator * (_3DVector vec, float num)
{
_3DVector v = new _3DVector();
v.X = num * vec.X;
v.Y = num * vec.Y;
v.Z = num * vec.Z;

return v;
}

From the examples I am following this should work but, I get an error when
I try to build the solution which says

One of the parameters of a binary operator must be the containing type.

I do not understand what this means. Any help will be appreciated.
It means the operator must be inside either the _3DVector class or the float
class. As it can't obviously be in float it has to be in the _3DVector
class.
 
C

chanmm

Can you show the code on how do you get the error. But do you will
understand operator overloading?

chanmm
 
Ad

Advertisements

B

billq

Hello Mike and Chanmm, thanks for the response. I moved the operator
into the _3DVector class and all works well.
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

overloading 4
Overloading 31
Overloading or not? 2
OVERLOADING 1
Overloading [] 5
lock and overloads 5
operator overloading 1
Operator Overloading? 4

Top