Menu

WIndows / C++

2003-01-22
2012-09-26
  • Derek Baker

    Derek Baker - 2003-01-22

    Looking on the 'net, there seem to be two solutions on the problem of callback and classes:

    making the function static

    using a global function to pass the parameters on to a class member function

    Does anyone have any opinions on which to use?

    Thanks in advance

    Derek

     
    • Nobody/Anonymous

      I would make the member function static... less sloppy more portable in my opinion...

      Zero Valintine

       
    • Derek Baker

      Derek Baker - 2003-01-22

      Thanks for the constructive reply Zero, I'd been expecting something like "whichever you like"!

      Anyone else?

      Derek

       
    • Anonymous

      Anonymous - 2003-01-22

      The problem with static function sis that they cannot access non-static members, which may be a problem. In situations where it is, I have used a static function that takes an instance pointer as a parameter.

      e.g.
      static void myClass::callback( myClass* instance ) ;

      In callback(), member functions and data may be called through the instance parameter.

      If you base myClass on a generic base class where callback() is a virtual function. The class registering the callback would therefore only need to know about the base class making the mechanism generic.

       
    • Derek Baker

      Derek Baker - 2003-01-22

      To clarify, the callback function that I am referring to in this instance is a windows procedure. Initially, a single main procedure, afterwards a procedure for multiple child windows.

      Derek

       
    • Derek Baker

      Derek Baker - 2003-01-22

      Update:

      I now have it working using a static member function for the WndProc, at least as a single window.

      No doubt, more fun ahead as try to make it MDI and introduce multiple child window!

      Derek

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.