Skip to main content
gamedev.net
🔒 Locked

Class Function Pointers

Started by iGore May 26, 2002 at 12:45 PM 1 replies 550+ views
Original Post
iGore
iGore
I hope someone can help me on this. I had this idea on how to speed up a game engine by using function pointers instead of just testing to see whether this option or that option is enabled. I ran into a problem. This is what I need: Using C++ (preferably VC++ 6.0) I want a class to hold a function pointer to one of it''s own members. I''ve had problems creating and calling the function. "non-function call" error has come up frequently. If someone can explain how to do this or point me in the right direction to find out how I can, I would be very grateful. Finally, I have been to www.function-pointer.org and that doesn''t explain what I want to find out. -Thanx- -iGore Productions-
-iGore-
jenova
jenova
there really is no basic way to do it because __thiscall is not a valid call type under VC++.

what you probably have to do is declare a member
void (__stdcall *func)(void); and then do something like....


  
__asm {
mov ecx, this
call func
}


To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Shannon Barber
Shannon Barber
There's a straight-forwrd way to do this, it's asked about once a month or so (FAQ Question!!!)
e.g.

typedef UINT (Class::*MethodProc)(void);
MethodProc pMethod;
//Use
UINT x = (pClass->*pMethod)();


There are some exceptions, but there's usually a more OO way of doing what you want using a design pattern or an interface based design - both of which are easier to manage.

Magmai Kai Holmlor

"Oh, like you've never written buggy code" - Lee

[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]

[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows]

Shamelessly ripped from Oluseyi


[edited by - Magmai Kai Holmlor on May 26, 2002 2:08:22 PM]
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.