how do you perform operator overloading using binary operators?
Yes, Yes it is a homework problem, it is just that i cant understand overloading bit..
isn't this a binary operator statement -->
how do you overload that?
post# 69 yay!!
Last edited by ihsir; 02-06-2002 at 09:53 AM.
operator overloading is discussed in the following link:
The simplist declaration of an overloaded binary operator for class T would be something like this:
//default constructor assigns value of 0 to data
//single parameter cconstructor assigns input to data
T T::operator+(const T &)
with definition like this:
T T::operator+(const T & rhs)
temp.data = data + rhs.data;
and used in program like this:
T example1(3), example2(18);
result = example1 + example2;
cout << result.data;
But read the chapter for a more sophisticated discussion and other examples.
great link Unregistered, but is there a way to do it without using of classes,constructors etc
No, you can't create global overloads for the binary operators.
Use a friend
if you do not want it to be a class member.
try this: friend T operator + (int n, T whatever )