Arrays of pointers to functions - Still confused here...

I am thankful for input on my former post, but it really did not answer my question. I am also sorry for mistyping the title....

- cin.get(cr); ????

- (*func_table[c - 'a'])(); How do you read this ?

Why both the variables 'c' and 'cr' ? And exactly how does
it work when the user input 'c' is deducted by 'a' ?
Why couldn't you use : (*func_table[c])(); to dereference the array pointer and call the function ?

Here is the code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

#define DF(N) void N() 
{
cout << " Function " #N " called......." << endl;
}

DF(a); DF(b); DF(c); DF(d); DF(e); DF(f); DF(g);

void (*func_table[])() = {a,b,c,d,e,f,g};

int main() {
while(1) {
cout << "press 'a' key from a to 'g' " "or 'q' to quit << endl;
char c, cr;
cin.get(c); cin.get(cr); 
if ( c == 'q')
break;
if(c < 'a' || c > 'g')
continue;
(*func_table[c - 'a'])();
}
} 
Last edited on
If you have more questions then ask them in that thread, rather than creating a new one for the same topic.
Topic archived. No new replies allowed.