I have the following function
typedef std::function<void(const data<3> & data, void * userData )> callbackFnc;
and some structure
typedef struct
{
callbackFnc callback;
void * userData;
} callbackData;
I store all these inside of my class in vector
std::vector<std::shared_ptr<callbackData> > mCallbacks;
This is how I add it:
bool MyClass::addCallback(callbackFnc cbFunc, void * userData)
{
std::shared_ptr<callbackData> cb = std::make_shared<callbackData>();
cb->callback = cbFunc;
cb->userData = userData;
mCallbacks.push_back(cb);
}
Now I want to check that the given function has been added and remove it. To do this I just compare function's address like this:
for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++)
{
// Compare address of these two functions
if ((&(*it)->callback) == &cbFunc)
{
mCallbacks.erase(it);
result = true;
break;
}
}
Looks like this comparison is not correct, but I can't figure out why. Any advice will be useful.
Thanks!