Two way class access
-
Hi all! I have the following class and i want a way to make the tree, and edit controls to have access to MAINCLASS variables. a. Is that OK to create a constructor to each one of the controls to pass a parameter something like Window* wn; And use it as ((MAINCLASS *)mainwindow)->a; within class implementation ? Or can you suggest me an other OOP way because i have read somewhere that this way to convert a base class object (mainwindow) to a derived class object is not so legal? class MAINCLASS: public window { ... ... public: //constructor //destructor MyTreeCtrl tc; MyEditCtrl ec; ... ... public: // Variables int a; } a. // in MyTreeCtrl h class MyTreeCtrl { ... ... public: MyTreeCtrl(Window* wn) void Foo(); ... ... public: // Variables Window *mainwindow; }; // in MyTreeCtrl cpp MyTreeCtrl::MyTreeCtrl(Window* wn) { mainwindow = wn; } MyTreeCtrl::void Foo() { ... int b = ((MAINCLASS *)mainwindow)->;a ... } Thanks!
-
Hi all! I have the following class and i want a way to make the tree, and edit controls to have access to MAINCLASS variables. a. Is that OK to create a constructor to each one of the controls to pass a parameter something like Window* wn; And use it as ((MAINCLASS *)mainwindow)->a; within class implementation ? Or can you suggest me an other OOP way because i have read somewhere that this way to convert a base class object (mainwindow) to a derived class object is not so legal? class MAINCLASS: public window { ... ... public: //constructor //destructor MyTreeCtrl tc; MyEditCtrl ec; ... ... public: // Variables int a; } a. // in MyTreeCtrl h class MyTreeCtrl { ... ... public: MyTreeCtrl(Window* wn) void Foo(); ... ... public: // Variables Window *mainwindow; }; // in MyTreeCtrl cpp MyTreeCtrl::MyTreeCtrl(Window* wn) { mainwindow = wn; } MyTreeCtrl::void Foo() { ... int b = ((MAINCLASS *)mainwindow)->;a ... } Thanks!
one suggestion (Off Topic) : Please use code block tags for posting code. Also indent the code so it is readable. Now about the topic. You can use forward declaration to solve your problem. Check this link for example : Forward declaration[^]
Regards, Sandip.