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 on other sites
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 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 on other sites
thank you * 2, I understand..

Create an account

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627653
• Total Posts
2978433

• 10
• 12
• 22
• 13
• 33