今天ebay 5%Ebucks,有什么可买的么?# Hardware - 计算机硬件
w*g
1 楼
/thinking in C++/第三章最后一个程序,硬是看不懂, 请高手指点一下:
//: C03:FunctionTable.cpp
// Using an array of pointers to functions
#include
using namespace std;
// A macro to define dummy functions:
#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 };
//以上function定义怎么理解,a,b,...g,是arguments还是statments?
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); // second one for CR
if ( c == 'q' )
break; // ... out of while(1)
if ( c < 'a' || c > 'g' )
continue;
(*func_table[c - 'a'])();
//以上一句为什么不能改成:(*func_table[c])();
}
} ///:~
Thanks!
//: C03:FunctionTable.cpp
// Using an array of pointers to functions
#include
using namespace std;
// A macro to define dummy functions:
#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 };
//以上function定义怎么理解,a,b,...g,是arguments还是statments?
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); // second one for CR
if ( c == 'q' )
break; // ... out of while(1)
if ( c < 'a' || c > 'g' )
continue;
(*func_table[c - 'a'])();
//以上一句为什么不能改成:(*func_table[c])();
}
} ///:~
Thanks!