Thread: Function pointer to class member?

  1. #1
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263

    Function pointer to class member?

    first im using MSVC and an MFC app, i dont use MSVC often nor do i use MFC often so...

    ok here's the deal im setting up a WM_TIMER and i have to declare the timer callback function as a class member so it can access the class members.

    it works fine except when its a class member.

    everytime i get

    error C2664: 'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned int,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,u
    nsigned int,unsigned long)'

    im not keen on C++ so is there a special way to declare member functions pointers is it even possible?

    any suggestions on workarounds?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  2. #2
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    hey no-one, lord knows why i'm at all qualified to answer your question, but i'll try for kicks anway. i've read that you should never have a member function _return_ a reference/pointer. it talks mainly of violating encapsulation--is that what you mean.

    if not, it also says never use -> or * when pointing to a class member. it offers this instead (which seems like the same thing to me:
    Code:
     void (test::*memPtr)() = &test::functino;
    but i have no idea what i'm talking about,

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    well this might work for classes(as i said im not keen in C++ though not so in C) but unforunatly the functions was designed for a non class member function pointer...so im thinking im screwed into using a global class pointer, not as elegant as i would have liked to handled it, but what can ya do.

    thanks anyway, i appreciate it, believe me.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Pointer to a class inside the WindowsProcedure function
    By like_no_other in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2009, 12:52 PM
  3. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  4. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  5. casting a void* to a pointer to a member function
    By Sebastiani in forum C++ Programming
    Replies: 13
    Last Post: 10-15-2002, 08:57 AM