CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Object arithmetics (http://www.cfd-online.com/Forums/openfoam-solving/59830-object-arithmetics.html)

shuo February 7, 2007 07:19

Hello I am trying to modify
 
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;
}


All times are GMT -4. The time now is 22:49.