Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / C++ Function Pointer Question

Author
Message
Lich120
18
Years of Service
User Offline
Joined: 19th Mar 2006
Location:
Posted: 30th May 2007 12:31
I know this isn't exactly DGDK related but it is a problem Im having while writing a program using the DGDK. Hopefully someone can help me figure out my problem.

Heres the problem:

I created a Menu Class to help manage my Menu objects in the game I'm making and to streamline their creation. This being said, one of the objects held inside the Menu Class is of Type Button. Naturally being that its a button I want it to do something when its clicked. So to accomplish this I have the program pass a Function Pointer to whatever function I want it to use when its clicked and have the pointer to this function stored with the Class Button.

The problem is, I get an Access violation when I try to call the function. I don't know if its a heap vs. stack issue where the function is being moved in memory so the call to memory is bad. I did get many different applications to work as long as my pointers and functions were in the same file... At any rate has anyone had this problem before or have any input? Thanks in advance.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th May 2007 15:12
Is it a plain function pointer or a member function pointer you are passing? Don't forget that to call a member function you need an object to invoke it against.

Lich120
18
Years of Service
User Offline
Joined: 19th Mar 2006
Location:
Posted: 1st Jun 2007 00:06
Ahh thanks IanM that was it. I did a google of the difference between Pointer to funtions and pointer to member functions and found how to properly access a member function. Didn't realize there was a difference. It also explains why I could get my simple applications to work because I wasn't embedding the function in a class in those. So thanks again.

Login to post a reply

Server time is: 2024-10-09 00:21:34
Your offset time is: 2024-10-09 00:21:34