Hi, I've got a class design problem. Well, actually it's not a big problem. I can somewhat make the class but I don't quite confidence that what I built was a good OOP practice.
I have two class for two different object. They have an integer as state. If one object changes the state, the other changed too. Here's what I've done:
And in the main class, I referenced the C class. Is it okay to do that? Is my code a good practice? Or is there any other better way to do that?Code:class A { private: int mState; public: inline void changeState(int state) { mState=state; } }; class B { private: int mState; public: inline void changeState(int state) { mState=state; } }; class C { private: A mA; B mB; public: void changeStateA(int state); void changeStateB(int state); }; void C::changeStateA(int state); { mA(state); switch(state) { 1: 4: mB(1); break; 2: 5: mB(1); break; 3: 6: mB(1); break; } } void C::changeStateB(int state); { mB(state); mA(state); }
Thanks in advance.



LinkBack URL
About LinkBacks



CornedBee
). Okay so to put it bluntly, I'll change my question to: How do I make 2 objects from 2 different classes that can know each other's change of value?