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. C++ Multiple inheritance

C++ Multiple inheritance

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++hardwareoopquestion
22 Posts 6 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.
  • L led mike

    That makes no sense at all. In that scenario the class has no control over the thread function and therefore the concept of encapsulation does not exist.

    ScotDolan wrote:

    The purpose of bool CreateNewThread(PTHREADFUNC pThreadFunc); is so ClxThread can be used without having to be inherited. So, i can declare a ClxThread object inside of mainloop instead of inheriting clxthread.

    For that scenario why wouldn't you declare an inherited class "inside of mainloop"? :confused:

    led mike

    S Offline
    S Offline
    ScotDolan
    wrote on last edited by
    #21

    For that scenario why wouldn't you declare an inherited class "inside of mainloop"? Mike, That is exactly what I am trying to do. However, I want mainloop to inherit ClxThread. but i also need it to inherit a Poll_Invertors. The problem is Poll_Invertors also inherits a ClxThread to create its own thread. The results is i end up with only one thread even being started ie basicly dreaded diamond.

       mainloop                           
         /  \\
        /    \\
       /      \\
      /        \\
    

    ClxThread Poll_Invertors
    \
    \
    \
    ClxThread

    The mainloop code class mainloop : public Poll_Invertors, public ClxThread { public: mainloop(); ~mainloop(); void Start(void){ CreateNewThread( ); };// Start Clx thread objecty protected: // The Setup Function the MC362X void init_mc362X(void); bool read_mc362x(void); bool read_lenze_cfg_sheet(void); bool read_independencer( void ); private: void ThreadRun( void ); // This is function that becomes the worker thread. MC362X_MOTION isacard; //Defines Motion object ClxUdp cmd_socket; // ClxUdp data_socket; // } The Poll_Invertors Header lass LENZE_8200_MOTION : public ClxThread, protected CLX_LENZE_8200 { public: LENZE_8200_MOTION(void); ~LENZE_8200_MOTION(void); public: bool init_lenze8200( int comm_port, int baud_rate, long timeout_ms, int maxtxfailures ); bool start_lenze8200(void){ return CreateNewThread(); } //These public member functions are to set, get and control Lift axis lenze 8200 inverter // These function provide a thread safe way to access data member variables that contain // lift axis status information and perform commands. void pitch_set_address( char address ){ return SetAddress( &pitch_axis_data, address ); }; ... char pitch_get_address( void ){ return GetAddress( &pitch_axis_data ); }; private: void ThreadRun(void); // This is the thread function that polls the invertors void RunAll( void ); LNZ82_INVRT_DATA pitch_axis_data; LNZ82_INVRT_DATA roll_axis_data; LNZ82_INVRT_DATA lift_axis_data; LNZ82_INVRT_DATA counterweight_axis_data; ClxSafeQue m_sqInvertorsCmdQue; char m_iInvertorsPollState; char pitch_init(LNZ82_INVRT_DATA *axis); char roll_init(LNZ82_INVRT_DATA *axis); char lift_init(LNZ82_INVRT_DATA *axis); char counterweight_init(LNZ82_INVRT_DATA *axis);

    L 1 Reply Last reply
    0
    • S ScotDolan

      For that scenario why wouldn't you declare an inherited class "inside of mainloop"? Mike, That is exactly what I am trying to do. However, I want mainloop to inherit ClxThread. but i also need it to inherit a Poll_Invertors. The problem is Poll_Invertors also inherits a ClxThread to create its own thread. The results is i end up with only one thread even being started ie basicly dreaded diamond.

         mainloop                           
           /  \\
          /    \\
         /      \\
        /        \\
      

      ClxThread Poll_Invertors
      \
      \
      \
      ClxThread

      The mainloop code class mainloop : public Poll_Invertors, public ClxThread { public: mainloop(); ~mainloop(); void Start(void){ CreateNewThread( ); };// Start Clx thread objecty protected: // The Setup Function the MC362X void init_mc362X(void); bool read_mc362x(void); bool read_lenze_cfg_sheet(void); bool read_independencer( void ); private: void ThreadRun( void ); // This is function that becomes the worker thread. MC362X_MOTION isacard; //Defines Motion object ClxUdp cmd_socket; // ClxUdp data_socket; // } The Poll_Invertors Header lass LENZE_8200_MOTION : public ClxThread, protected CLX_LENZE_8200 { public: LENZE_8200_MOTION(void); ~LENZE_8200_MOTION(void); public: bool init_lenze8200( int comm_port, int baud_rate, long timeout_ms, int maxtxfailures ); bool start_lenze8200(void){ return CreateNewThread(); } //These public member functions are to set, get and control Lift axis lenze 8200 inverter // These function provide a thread safe way to access data member variables that contain // lift axis status information and perform commands. void pitch_set_address( char address ){ return SetAddress( &pitch_axis_data, address ); }; ... char pitch_get_address( void ){ return GetAddress( &pitch_axis_data ); }; private: void ThreadRun(void); // This is the thread function that polls the invertors void RunAll( void ); LNZ82_INVRT_DATA pitch_axis_data; LNZ82_INVRT_DATA roll_axis_data; LNZ82_INVRT_DATA lift_axis_data; LNZ82_INVRT_DATA counterweight_axis_data; ClxSafeQue m_sqInvertorsCmdQue; char m_iInvertorsPollState; char pitch_init(LNZ82_INVRT_DATA *axis); char roll_init(LNZ82_INVRT_DATA *axis); char lift_init(LNZ82_INVRT_DATA *axis); char counterweight_init(LNZ82_INVRT_DATA *axis);

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #22

      At this point we are having a communication breakdown. I sugggest you take a fresh look at your design. statements like: "I want mainloop to inherit ClxThread. but i also need it to inherit a Poll_Invertors." indicate that you are experiencing myopia. Step away from that thinking completely and try to see a different approach.

      led mike

      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