CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > OpenFOAM

Converting objects

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Search this Thread Display Modes
Old   November 6, 2006, 16:37
Default Say a have two classes: cla
Posts: n/a
Say a have two classes:

class A {

double variable[30];


void show_variable();


class B {

double variable[30];


void show_variable();


How to I convert from one to another so that when equate them A = B, variable[30] of class A = variable[30] of class B?


  Reply With Quote

Old   November 6, 2006, 16:51
Default Define an assignment operator.
Posts: n/a
Define an assignment operator. I think the following will work, but it's not at all tested.

class B{
double variable[30];
B& operator= (const A&);

B& B::operator= (const A& objA) {
for (int i=0; i<30; i++)
variable[i] = objA.variable[i];
return *this;

Of course, that also needs to have access to A's internals, so you declare it as a friend of A:

class A{
double variable[30];
void show_variable();
friend B& B::operator= (const A&);
  Reply With Quote


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Rotating objects Marcus Gellert (Gellert) OpenFOAM Running, Solving & CFD 17 December 14, 2010 15:06
Warning when I add my objects Xu Phoenics 0 November 21, 2008 12:30
Objects in PRE and POST ? Felix CFX 0 January 16, 2008 15:53
CAD objects to PHOENICS bathman Phoenics 3 January 29, 2003 17:03
moving objects fan jinglng Phoenics 0 August 26, 2002 03:58

All times are GMT -4. The time now is 21:28.