CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Object arithmetics

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 7, 2007, 07:19
Default Hello I am trying to modify
  #1
shuo
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;
}
  Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 05:08.