I'm trying to make a map of ints and function pointers. I had never heard of function pointers until now and I have a few questions.
Here's what I've got so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <map>
#include <iostream>
using namespace std;
void testFunc()
{
cout<<"It works!\n";
}
int main()
{
map<int, void (**)()> mymap;//Why are 2 *'s required?
void (*tt)()=&testFunc;//Why is this required?
mymap[1]=&tt;
void (**final)();// why cant this be void (*final)();?
final=mymap.find(1)->second;
(*final)();
return 0;
}
|
I mostly don't understand where the double *'s came from and why they are required to compile.
And why is
void (*tt)()=&testFunc;
required? if it was a map of int* I could just
1 2 3 4
|
int x=5;
map <int, int*>maptwo;
maptwo[1]=&x;
|
Thanks!
Last edited on
Seems I over complicated things and confused myself.
Thanks!