473,237 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 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 1559
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
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
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
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
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
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
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
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
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
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
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.