0
0

Instead of a global static Callback i like to have an callback to a class.

Add a new .h file called “callback.h” for example and put in there something like
[code:3s0kq9sl]template < class Class, typename ReturnType, typename Parameter>
class ClassCallBack
{
public:
typedef ReturnType (Class::*Method)(Parameter);

ClassCallBack(Class* _class_instance, Method _method)
{
   class_instance = _class_instance;
   method         = _method;
};
ReturnType operator()(Parameter parameter)
{
   return (class_instance-&gt;*method)(parameter);
};
ReturnType execute(Parameter parameter)
{
   return operator()(parameter);
};

private:
Class* class_instance;
Method method;
};[/code:3s0kq9sl]

In our C code we use something like:
[code:3s0kq9sl]class AClass
{
public:
int Callback(char* foo)
{
std::cout << "Callback called" << std::endl;
};
};

AClass* inst1;
ClassCallBack< AClass, int, char*>cb(inst1,&AClass::Callback);
FMOD_Callback(cb);
[/code:3s0kq9sl]

Then fmod can execute:
[code:3s0kq9sl]cb("foo")[/code:3s0kq9sl]

Or is this kind of callbacks already in FmodEx ?

P.S. Good examples about callbacks is here: http://www.partow.net/programming/templatecallback/

  • You must to post comments
0
0

Why not do this yourself? I’m pretty sure you can. Those of us using VB or Delphi or C# aren’t going to get much help from a C++-specific callback system :)

Also, the code you posted doesn’t work for classes of an unknown type, so I don’t really see how it would be helpful…

  • You must to post comments
0
0

Hmm good point there, i never thought about all others. My bad 😳

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.