Original Post
Hi there. I'd like to be able to pass classes with operator() to a function which takes other functions as arguments. Can't get it right though :( Any thoughts on how to overcome this?
typedef void (*FuncPtr)();
void DoStuffWithFuncPtr(FuncPtr p)
{
p();
}
void SomeFunc()
{
// Implementation
}
class CSomeClass
{
public:
CSomeClass() {}
~CSomeClass() {}
void operator()() { /* Implementation */ }
};
void main()
{
CSomeClass instance;
// Doesn't work!
DoStuffWithFuncPtr(instance);
// "error C2664: 'DoStuffWithFuncPtr' : cannot convert parameter 1 from 'CSomeClass' to 'FuncPtr'
// No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called"
// This naturally works though
DoStuffWithFuncPtr(SomeFunc);
}