Jump to content
  • Advertisement
Sign in to follow this  
Hermes

+ operator

This topic is 5055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

why can't i overload the + operator like this? friend CVector3 operator+(CVector3& v1,CVector3& v2); ThankX in advance!

Share this post


Link to post
Share on other sites
Advertisement
I tried it but doesn't work
f:\visualc++6.0\myprojects\main\vector3.h(24) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information

Share this post


Link to post
Share on other sites
An internal compiler error means there's a bug in the compiler, not the code. Although why is the "friend" declaration there?

This works fine for me:

class CVector
{
public:
float x, y, z;
CVector(float _x, float _y, float _z) { x = _x; y = _y; z = _z; }
CVector operator+(const CVector& v2) const
{ return CVector(x+v2.x, y+v2.y, z+v2.z); }
};

This also works fine for me:

class CVector
{
public:
float x, y, z;
CVector(float _x, float _y, float _z) { x = _x; y = _y; z = _z; }
};

inline CVector operator+(const CVector& v1, const CVector& v2)
{
return CVector(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
}

Share this post


Link to post
Share on other sites
Well maybe i should try the inline...you see using binary operator +,-...etc is forbiden by the compiler unless you declare it as friend.i used that a few times without problems i can't see why it doesn't work now

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!