Skip to main content
gamedev.net
🔒 Locked

Operator Overloading?

Started by bikola_p Jun 11, 2006 at 1:15 AM 2 replies 600+ views
Original Post
bikola_p
bikola_p
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 ?
Kazade
Kazade
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.
Member of the NeHe team.
Driv3MeFar
Driv3MeFar
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;}
bikola_p
bikola_p
thank you * 2, I understand..

Topic Locked

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

Sign in to reply to this topic.