map<> and function pointers

  • Thread starter Thread starter DaTurk
  • Start date Start date
D

DaTurk

Hi, I'm trying to hold a map of ints,and function pointers in C++

map<int, (*functPtr)(int, int)> something

I need to hold a list of callbacks. For some reason this syntax is
not working. Any ideas?
 
Hi,
Hi, I'm trying to hold a map of ints,and function pointers in C++

map<int, (*functPtr)(int, int)> something

I need to hold a list of callbacks. For some reason this syntax is
not working. Any ideas?

At least you are missing a return type. C hat int as default but C++ wants
it explicitly. In your case void I assume.

I prefer typedef'ing function pointers as it makes code using those pointer
types easier. You might try this:

typedef void (*funcPtr)(int, int);
std::map<int, funcPtr> something;
 
SvenC said:
Hi,


At least you are missing a return type. C hat int as default but C++ wants
it explicitly. In your case void I assume.

Also, the template needs a type only, no name.

So:
 
Back
Top