Peter Hull
2008-06-20 07:48:16 UTC
What's the best way to add closures to a list?
I've got some code like this
typedef void (__closure *NotifyFunc)(AnsiString);
...
TList* notifier_list;
...
void AddNotifier(NotifyFunc nf)
{
notifier_list->Add((void*) nf);
}
But I get an error because it cannot convert NotifyFunc to void*
I can get round it with a wrapper:
struct Wrapper {
Wrapper(NotifyFunc _nf) : nf(_nf) {}
NotifyFunc nf;
};
...
void AddNotifier(NotifyFunc nf)
{
notifier_list->Add(new Wrapper(nf));
}
Or I can use std::list<NotifyFunc>
But is there a better way?
Pete
I've got some code like this
typedef void (__closure *NotifyFunc)(AnsiString);
...
TList* notifier_list;
...
void AddNotifier(NotifyFunc nf)
{
notifier_list->Add((void*) nf);
}
But I get an error because it cannot convert NotifyFunc to void*
I can get round it with a wrapper:
struct Wrapper {
Wrapper(NotifyFunc _nf) : nf(_nf) {}
NotifyFunc nf;
};
...
void AddNotifier(NotifyFunc nf)
{
notifier_list->Add(new Wrapper(nf));
}
Or I can use std::list<NotifyFunc>
But is there a better way?
Pete