Operator overloading wierdness

T

twonjosh

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
 
P

Peter Koch Larsen

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
 
V

Victor Bazarov

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
 
P

Prawit Chaivong

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?
 
R

Ralph D. Ungermann

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::eek:perator*()
- jMatrix44::eek:perator*()
(These will hide your friend declaration, no matter, what arguments they
take).


HTH,
Ralph
 

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

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top