|
[Sponsors] |
![]() |
![]() |
#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 |
|
![]() |
![]() |
![]() |
#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&); }; |
|
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Rotating objects | Marcus Gellert (Gellert) | OpenFOAM Running, Solving & CFD | 17 | December 14, 2010 16:06 |
Warning when I add my objects | Xu | Phoenics | 0 | November 21, 2008 13:30 |
Objects in PRE and POST ? | Felix | CFX | 0 | January 16, 2008 16:53 |
CAD objects to PHOENICS | bathman | Phoenics | 3 | January 29, 2003 18:03 |
moving objects | fan jinglng | Phoenics | 0 | August 26, 2002 04:58 |