|
-
Jul 1st, 2002, 04:46 PM
#1
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.
-
Jul 1st, 2002, 04:56 PM
#2
Frenzied Member
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."
-
Jul 1st, 2002, 05:03 PM
#3
Frenzied Member
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."
-
Jul 1st, 2002, 05:45 PM
#4
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.
-
Jul 1st, 2002, 06:11 PM
#5
Frenzied Member
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."
-
Jul 1st, 2002, 06:27 PM
#6
Nope, ive tried almost everything i can think of and nothing works.
-
Jul 1st, 2002, 06:39 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|