Skip to main content
gamedev.net
🔒 Locked

overloading

Started by DarkEmpire Aug 7, 2002 at 6:59 AM 1 replies 250+ views
Original Post
DarkEmpire
DarkEmpire
Hi all, Is there a tip to overload the "=" operation only with any conditions. ex: i would want to overload the = operation only if pointers are concerned ie: int *a, *b; ... b = a <- i want to overload int c,d d = c <- not overloading. CMyObject *o1, *o2; ... o2 = o1 <-- overload Thanks
walkingcarcass
walkingcarcass
the general case is

returntype operator[op](a,b){
code...
}

example:
vector operator+(const vector& p1,const vector& p2){
vector temp;
temp.x = p1.x + p2.x;
etc...
return temp;
}

would be used like:
vector a,b,c;
a = b+c;

********


A Problem Worthy of Attack
Proves It''s Worth by Fighting Back
spraff.net: don't laugh, I'm still just starting...
SabreMan
SabreMan
A binary operator can only be overloaded when one of the types is user-defined. If both types are pointers, then you cannot overload.

Topic Locked

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

Sign in to reply to this topic.