471,354 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

map<> and function pointers

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?

Jul 12 '07 #1
2 1483
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, funcPtrsomething;

--
SvenC

Jul 12 '07 #2

"SvenC" <Sv***@community.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
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.
Also, the template needs a type only, no name.

So:

map<int, void (*)(int, int)something;
>
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, funcPtrsomething;

--
SvenC
Jul 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sachin_mzn | last post: by
3 posts views Thread by mcassiani | last post: by
6 posts views Thread by Juha Nieminen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.