Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Two way class access

Two way class access

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dennis L
    wrote on last edited by
    #1

    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!

    S 1 Reply Last reply
    0
    • D Dennis L

      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!

      S Offline
      S Offline
      SandipG
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups