Results 1 to 7 of 7

Thread: C++ Function pointer

  1. #1
    ChimpFace9000
    Guest

    Post C++ Function pointer

    I have class thats called game. In the class theres a pointer called m_pDisplay. Its a pointer to a function in the class game. Then another class, CWindow, has a pointer to a game class. In the window class, how do i call the pointer in the game class?

    I thought something like... m_pGame is the game pointer.
    Code:
    m_pGame->m_pDisplay()
    But nope.

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Maybe my memory on this is rusty, but that looks fine to me. What's the error message?
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Just had a quick look around the net, and it seems that way might be the C-style syntax. Maybe it doesn't work in C++. Try this:

    Code:
    (*m_pGame.*m_pDisplay)();
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    ChimpFace9000
    Guest
    With...
    Code:
    m_pGame->m_pDisplay();
    I get this error...
    Code:
    window.cpp(125) : error C2064: term does not evaluate to a function
    With...
    Code:
    (*m_pGame.*m_pDisplay)();
    I get this error...
    Code:
    window.cpp(125) : error C2065: 'm_pDisplay' : undeclared identifier
    window.cpp(125) : error C2297: '.*' : illegal, right operand has type 'int'
    It says undeclared identifier, but it definitly is a declared identifier cuz in the game class i initilize to point to a function. And m_pDisplay is public.

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    uhh.. okay... maybe more parentheses are needed? Clutching at straws here....

    Code:
    (*((*m_pGame).m_pDisplay))();
    I'm sure some of those aren't necessary but I've forgotten exactly what the precedence is.
    Harry.

    "From one thing, know ten thousand things."

  6. #6
    ChimpFace9000
    Guest
    Nope, ive tried almost everything i can think of and nothing works.

  7. #7
    ChimpFace9000
    Guest
    This works...
    Code:
    (m_pGame->*(m_pGame->m_pDisplay))();

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