473,513 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1574
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1763
by: sachin_mzn | last post by:
Hi, When we use find method over a STL map. which searching algorithm is used internally. Is it a hash search? Or map implementation internally decide depending on element. -Sachin
3
1423
by: mcassiani | last post by:
Hi, I need use map faster as possible (I store in the map data about open network connections). First a question, this code fragment is from "The C++ Programming........
10
2947
by: Szabolcs Horvát | last post by:
Consider the attached example program: an object of type 'A' is inserted into a 'map<int, Am;'. Why does 'm;' call the copy constructor of 'A' twice in addition to a constructor call? The...
2
2233
by: brzozo2 | last post by:
Hello, this program might look abit long, but it's pretty simple and easy to follow. What it does is read from a file, outputs the contents to screen, and then writes them to a different file. It...
3
2929
by: newbie | last post by:
Same thing g++ complains when using hash_map<>, but is happy with map<--I understand hahs_map is not standardized, but since the compiler didn't complain something like 'hash_map<not defined', I...
12
5810
by: jabbah | last post by:
Actually I'm quite sure I've missed something trivial here, but I just can't find it. Seemingly I cannot read from a const map& I try #include <iostream> #include <map> using namespace std;
2
2771
by: jabbah | last post by:
I have some data in a map and I want to sort it. Currently I have implemented it like this: #include <iostream> #include <map> #include <string> using namespace std; int main(){
6
7337
by: Mr. K.V.B.L. | last post by:
I want to start a map with keys but an empty vector<string>. Not sure what the syntax is here. Something like: map<string, vector<string MapVector; MapVector.insert(make_pair("string1",...
6
5411
by: Juha Nieminen | last post by:
joseph cook wrote: Not always. By default, yes, but you can specify other comparators, eg: std::map<int, int, std::greaterreversedMap;
0
7267
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.