From: tohava on
On Nov 4, 1: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;

What you are doing is the same as doing:
list<int i> intList;

You should not provide a name together with the type you
give the template.
I do not remember the proper syntax to solve your problem by:
typedef void (*func_t)(int id, void *message);
list<func_t> functionList;

{ edits: quoted banner removed. please don't quote the banner. -mod }

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

From: Daniel Krügler on
On 4 Nov., 00:28, 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;

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! ]

From: Zbigniew Kostrzewa on
> list<void(* functionName)(int id,void *message)> functionList;

With this you are passing a function pointer declaration as a template
parameter.
This is the same (syntactically) as:
list<int var> listOfInts;

You need to pass just a type declaration - do it this way:
list<void(*)(int,void*)> functionList;



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

From: Yechezkel Mett on
On Nov 4, 1: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;

Nearly. It should be:

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

functionName is not part of the type.

Alternatively:

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

The parameter names are not required (but are permitted) here.

Yechezkel Mett


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