So I want to create a callback function for my game objects as they handle messages so that game-specific actions can be taken. Clash pointed me toward the Boost Function and Bind libraries. Good stuff. The only problem I have is binding a function that has an argument. I of course would like to pass along the message currently being handled, after all. However it seems that if I were to create a callback like so:
typedef boost::function<void(DataPtr)> Callback;
and bind it like so:
obj->SetUserUpdateFunction(boost::bind(&CUIMngr::UpdateUI, UIManager));
Not only do I get a compiler warning:
..\mem_fn.hpp(256) : warning C4180: qualifier applied to function type has no meaning; ignored
But the VC++ Express compiler actually
crashes. Every time. I thought maybe I was calling bind() wrong, so I used the test code from the docs, and it compiled fine. Then on a hunch, I added an argument to the callback function and crash! boom! bang!
So I went back over the Boost::Bind docs and the only thing I could find was the reference to the Forwarding Problem. Does this mean I can't bind any functions with arguments? Or that I have to do a bit of hacking to get it to work properly? Or am I totally off the mark, you
can bind functions with arguments, and I'm missing somethign completely stupid? (wouldn't be the first time...)