|
[Sponsors] |
February 7, 2007, 07:19 |
Hello
I am trying to modify
|
#1 |
Guest
Posts: n/a
|
Hello
I am trying to modify the following code so that it can do object arithmatics ie.a*b + a without it inteperting it as a*b, storing the results in object a then adding it to the MODIFIED object a. I am not sure what to do with the *this pointers. Also say if I wanted to do a*b + c*d, is there any way of implementing order of operations so that it doesn't misintepret it as (a*b + c)*d Any advice? Cheers Shuo class Array{ int *ptr; public: Array(); ~Array(); int getSize() const; const Array &operator=(const Array &); int index(int, int); Array &operator+(Array &); Array &operator*(Array &); Array &operator-(Array &); Array &operator/(int); }; Example of overloaded function * // Overload * for ob1 * ob2. Array &Array::operator*(Array &right) { int i; for (i = 0; i < (arraySize); i++) ptr[i] = ptr[i] * right.ptr[i]; return *this; } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to determine the type of an object in the object registry | mwild | OpenFOAM Running, Solving & CFD | 8 | June 8, 2010 21:58 |
Rotating object | Braden Pitter | Phoenics | 0 | March 27, 2007 19:37 |
Error Object: nan | Kajal Mehta | FLUENT | 5 | August 1, 2005 13:49 |
CAD object | Hu | Phoenics | 2 | April 16, 2002 11:10 |
How to set an object | tokai | CFX | 1 | June 1, 2001 06:22 |