From: Sam Price on
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;

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Neil Butterworth on
Sam Price 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;

#include <list>
typedef void (*Func)(int, void*);
std::list <Func> flist;

Note that list lives in the std namespace.

Neil Butterworth



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Eric Johnson on
I believe this should work:

#include <list>

typedef void(* functionPtr)(int id,void *message);

std::list<functionPtr> myList;



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Ulrich Eckhardt on
Sam Price 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;

One basic up front: If you prefix a declaration (variable or function
doesn't matter) with a typedef, the name used there becomes an alias for
the type of the declaration.

Examples:
typedef int number;
typedef int array[10];
typedef int function();

Now, with that it becomes easy to create a list of function pointers:

typedef void message_handler(int id, void* message);
std::list<message_handler*> functionList;

> list<void(* functionName)(int id,void *message)> functionList;

list<void(* )(int ,void * )> functionList;

In other words, the name must not be there when you only need the type. I'm
not sure about the names of the parameters and leave that to the interested
reader to find out. ;)

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: marcin.sfider on
On Nov 4, 12:28 am, Sam Price <thesampr...(a)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;

Drop identifiers:

std::list<void (*)(int, void*)>

will do.

You could also consider using something like Boost::Function to
replace
staticly typed raw function pointer.

Cheers
Sfider


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]