473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

overload the *

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
Aug 16 '06 #1
3 3896
"billq" <bi********@comcast.netwrote in message
news:QI******************************@comcast.com. ..
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.
thanks
bill

Aug 16 '06 #2
Can you show the code on how do you get the error. But do you will
understand operator overloading?

chanmm

"billq" <bi********@comcast.netwrote in message
news:QI******************************@comcast.com. ..
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

Aug 16 '06 #3
Hello Mike and Chanmm, thanks for the response. I moved the operator
into the _3DVector class and all works well.
thanks

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

chanmm

"billq" <bi********@comcast.netwrote in message
news:QI******************************@comcast.com. ..
>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

Aug 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Piotre Ugrumov | last post by:
I have tried to implement the overload of these 2 operators. ostream & operator<<(ostream &out, Person &p){ out<<p.getName()<<" "<<p.getSurname()<<", "<<p.getDateOfBirth()<<endl; return out; }...
1
by: Piotre Ugrumov | last post by:
I'm following your help. I have written the overload of the operator <<. This overload work! :-) But I have some problem with the overload of the operator >>. I have written the overload of this...
3
by: Piotre Ugrumov | last post by:
I have done the overload on the operator >> and << in the class Attore. These 2 overload work correctly. I have done the overload of the same overload in the class Film. The class film ha inside...
4
by: Chiller | last post by:
Ok, thanks to some good assistance/advice from people in this group I've been able to further develop my Distance class. Since previous posts I've refined my code to accept the unit measurement...
9
by: Mario Charest | last post by:
.. Hi, It's possible to overload the operator, but I wonder if it's possible to somehow overload and so forth. My goal would be to switch from static array declaration into something...
17
by: Chris | last post by:
To me, this seems rather redundant. The compiler requires that if you overload the == operator, you must also overload the != operator. All I do for the != operator is something like this: ...
10
by: shachar | last post by:
hi all. can i OverLoad Operators - such as Exclamation Mark "!" ? how?
9
by: Tony | last post by:
I have an operator== overload that compares two items and returns a new class as the result of the comparison (instead of the normal bool) I then get an ambiguous operater compile error when I...
3
by: i3x171um | last post by:
To start off, I'm using GCC4. Specifically, the MingW (setjmp/longjmp) build of GCC 4.2.1 on Windows XP x64. I'm writing a class that abstracts a message, which can be either an integer (stored as...
5
by: jknupp | last post by:
In the following program, if the call to bar does not specify the type as <int>, gcc gives the error "no matching function for call to ‘bar(A&, <unresolved overloaded function type>)’". Since bar...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.