-
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.
-
Maybe my memory on this is rusty, but that looks fine to me. What's the error message?
-
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)();
-
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.
-
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.
-
Nope, ive tried almost everything i can think of and nothing works.
-
This works...
Code:
(m_pGame->*(m_pGame->m_pDisplay))();