Jump to content
  • Advertisement
Sign in to follow this  
bikola_p

Operator Overloading?

This topic is 4484 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

Hey, im quiet confused with this, basically i understand it is to allow say two user definend types to have workable operators, ie Having a class called Day. And creating an instance ie Day Today; Day Tomorow; Operator overloading would allow Today + Tomorow; is this correct? From what i understand i would have to do the defenition of the operator overloading in the class defenition. Day::operator++{ //increment member variables or whatever in here; return *this; } if that above is correct, i see it would work with Tody++; But how and what would i need to enable Today+Tomorow ?

Share this post


Link to post
Share on other sites
Advertisement
Try:


Day Day::operator+ (const Day &d) const
{
result = Variable + d.Variable
return result;
}



or something like that, its very early in the morning :)

Luke.

Share this post


Link to post
Share on other sites
I really can't understand you very well, but heres an example of operator overloading:


class CVector3
{
friend CVector3 operator+(CVector3 &rhs);

public:

...

}

...

CVector3 CVector3::operator+(CVector3 &rhs)
{
return CVector3(x + rhs.x, y + rhs.y, z + rhs.z);
}

...

int main()
{
CVector3 vec1(1.0, 1.0, 1.0);
CVector3 vec2(1.0, 1.0, 1.0);

CVector3 vec3 = vec1 + vec2;

return 0;
}


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!