convoluted function pointer, or...?

Started by
2 comments, last by Mr Grinch 16 years, 11 months ago
I'm working on an editor program that uses two classes; one controls the main window functionality, and one controls the 3d-display panel on the main window. As such, the second class is a member of the first class. I have a listbox control on the window that I want to update when the user performs an action on the 3d-display panel. Since the panel is a member of the main-window class, I'm having trouble figuring out how to call a function of the main-window class from the 3d-display panel class. I thought maybe a function pointer would do the trick, but I can't use the class name of the main-window from within the 3d-display. How should I go about doing this?
Advertisement
You could have the "main window" register callback functions (in the form of function pointers) with the 3d-display window. Peruse these Google results to find some ideas of how to implement callbacks using class methods. It's very doable, and the 3d-window doesn't have to know anything about the "main window"... It just invokes whatever callbacks you give it.

Of course, if you are using a .NET/Mono language, you can use events/delegates, which are a very elegant solution.
Damn that's pretty complicated! Much more than I felt like dealing with right now; I just rigged up a quick workaround. Definitely some good material for a rainy day though...

Good lookin' out.
Take a look at boost::bind and especially how to use it with member functions.

This topic is closed to new replies.

Advertisement