469,927 Members | 1,724 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Operator overloading wierdness

Hello, i'm trying to make a simple friend function for multipling a
vector and a matrix together. I'm getting a very wierd error and I
don't know why. Here is the code snipits:

Friend function prototype:

jVector4 operator*(const jVector4& vec, const jMatrix44& mat);

Code sample...........

jVector4 test_vector;
jMatrix44 test_matrix;

test_vector * test_matrix;

............end code sample

That last line is giving me this error in VS.NET:

error C2678: binary '*' : no operator found which takes a left-hand
operand of type 'jVector4' (or there is no acceptable conversion)

Any ideas what i'm doing wrong?

Thanks,
-Josh

Jul 23 '05 #1
4 1382

<tw******@gmail.com> skrev i en meddelelse
news:11**********************@g43g2000cwa.googlegr oups.com...
Hello, i'm trying to make a simple friend function for multipling a
vector and a matrix together. I'm getting a very wierd error and I
don't know why. Here is the code snipits:

Friend function prototype:

jVector4 operator*(const jVector4& vec, const jMatrix44& mat);

Code sample...........

jVector4 test_vector;
jMatrix44 test_matrix;

test_vector * test_matrix;

...........end code sample

That last line is giving me this error in VS.NET:

error C2678: binary '*' : no operator found which takes a left-hand
operand of type 'jVector4' (or there is no acceptable conversion)

Any ideas what i'm doing wrong?
It is not enough to declare it as a friend. You should also declare it as a
stand-alone function.

/Peter
Thanks,
-Josh

Jul 23 '05 #2
tw******@gmail.com wrote:
Hello, i'm trying to make a simple friend function for multipling a
vector and a matrix together. I'm getting a very wierd error and I
don't know why. Here is the code snipits:

Friend function prototype:

jVector4 operator*(const jVector4& vec, const jMatrix44& mat);

Code sample...........

jVector4 test_vector;
jMatrix44 test_matrix;

test_vector * test_matrix;

...........end code sample
This sample is not large enough to diagnose the problem.
That last line is giving me this error in VS.NET:

error C2678: binary '*' : no operator found which takes a left-hand
operand of type 'jVector4' (or there is no acceptable conversion)

Any ideas what i'm doing wrong?


You're not following the recommendations of the FAQ 5.8.

V
Jul 23 '05 #3


tw******@gmail.com wrote:
Hello, i'm trying to make a simple friend function for multipling a
vector and a matrix together. I'm getting a very wierd error and I
don't know why. Here is the code snipits:

Friend function prototype:

jVector4 operator*(const jVector4& vec, const jMatrix44& mat);

Code sample...........

jVector4 test_vector;
jMatrix44 test_matrix;

test_vector * test_matrix; Try
jVector4 result = test_vector * test_matrix;

Does it work?

...........end code sample

That last line is giving me this error in VS.NET:

error C2678: binary '*' : no operator found which takes a left-hand
operand of type 'jVector4' (or there is no acceptable conversion)

Any ideas what i'm doing wrong?

Thanks,
-Josh


Jul 23 '05 #4
tw******@gmail.com wrote:
Friend function prototype:

jVector4 operator*(const jVector4& vec, const jMatrix44& mat);

Code sample...........

jVector4 test_vector;
jMatrix44 test_matrix;

test_vector * test_matrix;

...........end code sample

That last line is giving me this error in VS.NET:

error C2678: binary '*' : no operator found which takes a left-hand
operand of type 'jVector4' (or there is no acceptable conversion)

Any ideas what i'm doing wrong?

Hello Josh,

`no operator found' may mean
- there is none, or
- it is hidden

As your friend statement is an implicit declaration, I guess the latter:

Did you declare any of
- jVector4::operator*()
- jMatrix44::operator*()
(These will hide your friend declaration, no matter, what arguments they
take).
HTH,
Ralph
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Edward Diener | last post: by
2 posts views Thread by pmatos | last post: by
67 posts views Thread by carlos | last post: by
6 posts views Thread by jay | last post: by
3 posts views Thread by y-man | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.