CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   Object arithmetics (

shuo February 7, 2007 07:19

Hello I am trying to modify

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?


class Array{

int *ptr;



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;

All times are GMT -4. The time now is 20:32.