|
[Sponsors] |
November 6, 2006, 16:37 |
Say a have two classes:
cla
|
#1 |
Guest
Posts: n/a
|
Say a have two classes:
class A { double variable[30]; public: void show_variable(); }; and class B { double variable[30]; public: 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? Regards Shuo |
|
November 6, 2006, 16:51 |
Define an assignment operator.
|
#2 |
Guest
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]; public: show_variable(); 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]; public: void show_variable(); friend B& B::operator= (const A&); }; |
|
|
|
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 |