Skip to main content
gamedev.net
🔒 Locked

overloading operator

Started by avocados 3 replies 950+ views
Original Post
avocados
avocados
struct v3df { float x; float y; float z; };

v3df operator*( v3df &a, float f ) {
v3df c = { a.x*f, a.y*f, a.z*f };
return( c );
}

void func( ) {
v3df move = { 3,4,5 };
float friction = 0.9;

v3df move_update = move * friction;
}


The app runs correctly despite this error being produced:
error C2296: '*' : illegal, left operand has type 'v3df *'
Is there a way to make my overloaded operator not get caught by the normal operator error checking?
SiCrane
SiCrane
Interestingly the only + in your post is in the error. If you want a useful reply it would help if you posted the actual code that produced the error.
avocados
avocados
Sorry, fixed the error line in my post that mentioned '+'. I had copied the wrong error.
SiCrane
SiCrane
When throwing your code, as posted, into a compiler, it compiles fine. Nor do I see anything in your code with a pointer type as mentioned by the error message.
avocados
avocados
Wow am I error-prone today. I wasn't thinking when I made a new local variable for posting an example. I'll be sure to use unedited examples in the future. Thanks for your time.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.