Author Topic: How to use...  (Read 1987 times)

0 Members and 1 Guest are viewing this topic.


  • Guest
How to use...
« on: May 30, 2010, 06:42:50 AM »
AcGePoint2d operator *(double val, const AcGePoint2d& p)

Can't find anything in my books or online about overloaded arithmetic operators with multiple parameters.  Hence, how would such a thing be used?



  • Guest
Re: How to use...
« Reply #1 on: May 30, 2010, 08:32:43 AM »
Ok, got it figured out. The original question should have been "how to use or implement in a new class" as I already know how to use it as defined in ARX.

It falls under the classification of "Binary operator overloading", per IBM's website
Overloading binary operators (C++ only)
You overload a binary unary operator with either a nonstatic member function that has one parameter, or a nonmember function that has two parameters. Suppose a binary operator @ is called with the statement t @ u, where t is an object of type T, and u is an object of type U. A nonstatic member function that overloads this operator would have the following form:
Code: [Select]
return_type operator@(T)A nonmember function that overloads the same operator would have the following form:
Code: [Select]
return_type operator@(T, U)An overloaded binary operator may return any type.

To make this work within a class the member function must be turned into a non member function, so define it as a friend function which gives it global scope.

Code: [Select]
class Stuff
    Stuff   operator+(int nCount) { ... }
    Stuff & operator+(int nCount, const Stuff & stuff) { ... }
    Stuff & operator+(AcGePoint2d & pt, Stuff & stuff) { ... }
    const  Stuff & operator=(const Stuff &vec) { ... }

 Stuff st = Stuff() + 4;
 st = 4 + Stuff();
 st = AcGePoint2d(10,10) + Stuff();