Shawn Curry
10-14-2002, 07:33 PM
The books that I have on C++ dont really explain the difference in overloading binary and unary operators. I have a long math class to handle extremely large numbers. I overloaded pretty much all the binary operators for it(+, +=, -, -= etc) but it would be great if I could overload ++ and ! (for factorials). I tried to look it up on the net and it says to do it just like I overloaded the binaries. Is that right? and if so, what do I have to do differently?
class xNumber
{
public:
char* number;
public:
xNumber operator+(const xNumber&);
xNumber& operator+=(const xNumber&);
(...)
};
xNumber xNumber:: operator+(const xNumber& xn)
{
(...)
}
xNumber& xNumber:: operator+=(const xNumber& xn)
{
(...)
}
That's what my binary ops look like. Is it just in the way I handle it inside the function or what?
Thanks
class xNumber
{
public:
char* number;
public:
xNumber operator+(const xNumber&);
xNumber& operator+=(const xNumber&);
(...)
};
xNumber xNumber:: operator+(const xNumber& xn)
{
(...)
}
xNumber& xNumber:: operator+=(const xNumber& xn)
{
(...)
}
That's what my binary ops look like. Is it just in the way I handle it inside the function or what?
Thanks