PDA

Click to See Complete Forum and Search --> : C++ Function pointer


ChimpFace9000
Jul 1st, 2002, 04:46 PM
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.
m_pGame->m_pDisplay()

But nope.

HarryW
Jul 1st, 2002, 04:56 PM
Maybe my memory on this is rusty, but that looks fine to me. What's the error message?

HarryW
Jul 1st, 2002, 05:03 PM
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:

(*m_pGame.*m_pDisplay)();

ChimpFace9000
Jul 1st, 2002, 05:45 PM
With...
m_pGame->m_pDisplay();
I get this error...
window.cpp(125) : error C2064: term does not evaluate to a function
With...
(*m_pGame.*m_pDisplay)();
I get this error...
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.

HarryW
Jul 1st, 2002, 06:11 PM
uhh.. okay... maybe more parentheses are needed? Clutching at straws here....

(*((*m_pGame).m_pDisplay))();

I'm sure some of those aren't necessary but I've forgotten exactly what the precedence is.

ChimpFace9000
Jul 1st, 2002, 06:27 PM
Nope, ive tried almost everything i can think of and nothing works.

ChimpFace9000
Jul 1st, 2002, 06:39 PM
This works...
(m_pGame->*(m_pGame->m_pDisplay))();