Re: An stl list of function pointers
On 4 Nov., 00:28, Sam Price <thesampr...@gmail.com> wrote:
In my project I want to create a list of functions that I am going to
iterate over and call sequentially.
Im not quite sure how to define an stl list of function pointers.
#include <list>
my best guess that is wrong.
list<void(* functionName)(int id,void *message)> functionList;
1) Add a std:: qualifier in front of list.
2) Remove the "functionName" from the declaration, it is not part
of the declaration of a function pointer type description that is
part of another declaration (functionList). You probably mixed that
up with type declarations like
typedef void(* functionName)(int id,void *message);
where functionName is the declared name for the type
void(*)(int id,void *message). It is interesting to observe
that function parameters can be arbitrarily sprinkled,
even though they are redundant. So the second
declaration could be shortened to
typedef void(* functionName)(int,void*);
and the first one to
std::list<void(*)(int,void*)> functionList;
but this is rarely done because code readers often like to
understand what function parameters stand for.
If you want to provide a good name for the value type
of this list, you can combine both approaches:
typedef void(* call_back)(int,void*);
std::list<call_back> functionList;
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]