Results 1 to 6 of 6

Thread: Calling a pointer from a static member

  1. #1
    ChimpFace9000
    Guest

    Post Calling a pointer from a static member

    In my class i have a pointer to point to different functions and i want to use that pointer to call the functions from a static member of the class.

    I thought something like this would work...
    Code:
    (pPARENT.*m_pInputOnCharProc)(&wParam);
    But it doesnt. I get these errors...
    Code:
    cdlgmain.cpp(192) : error C2597: illegal reference to data member 'CDlgMain::m_p InputOnCharProc' in a static member function
    cdlgmain.cpp(192) : error C2568: '.*' : unable to resolve function overload
    pPARENT is the variable thats holding the "this" of the class.

    Any ideas?

  2. #2
    Zaei
    Guest
    You cant use any dynamic function or data in a static member. You could make the pPARENT variable static, and assign this to it every time you want to call the static function, but that seems a bit awkward. What are you trying to accomplish?

    Z.

  3. #3
    ChimpFace9000
    Guest
    What do you mean by dynamic? If you mean any of the non-static functions and variables, then your wrong. I just need the pointer, which i have.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    pParent is a pointer, so do:
    (pPARENT->*m_pInputOnCharProc)(&wParam);
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Zaei
    Guest
    But the pointer is not static, so you cannot access it inside of a static function. Think of it this way. There is only one instance of each static member function and variable for ALL classes. Dynamic functions (non-static) can easily use these functions and variables, because they know where they are stored, etc. But think about it the other way. How does a static function know where a dynamic variable is stored? Which one should it use? If I have 15 instances of some class, which one's pPARENT should I look at? So, you cannot access non-static members from a static member. It is impossible, unless you pass in a this pointer to the function (in which case, it shouldnt be a static function).

    Z.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I guess pPARENT is maybe a static member (bad idea) or a function parameter (also bad idea, like Zaei said, function should be normal method then).
    Or it is a pointer casted to the base class...
    Or this is a windows callback and pPARENT is casted from the lparam. (Actually the most probable, the name of the function pointer member indicates a WNDPROC)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width