Re: Exercise with array of pointers to func
Alex Blekhman wrote:
"Fil" wrote:
// A macro to define dummy functions:
#define DF(N) string N() { \
return "function " #N " called..."; }
You can use predefined macro for function name:
#define DF(N) string N() { \
return "function " __FUNCTION__ " called..."; }
DF(a); DF(b); DF(c); DF(d); DF(e); DF(f); DF(g);
The semicolon after the D macro is redundant.
Worse, a semicolon is an empty statement at function scope but at namespace
scope it is simply invalid. Some compilers actually give you errors for
that.
Note that a single semicolon is allowed after the inline definition of a
memberfunction, though I personally consider that an oversight in the
standard.
string ((*(func_table[]))()) = { &a, &b, &c, &d, &e, &f, &g };
You can use a typedef for a function to make that readable:
typedef string function_type(void);
function_type* func_table[] = { &a, &b, &c, &d, &e, &f, &g };
First of all, I'd suggest to use a typedef here, which will
simplify the code greatly:
typedef string (*my_func_t)();
This is another way, though the name is misleading. It should
be 'my_func_ptr_t' rather, because it is a typedef for a pointer rather
than for a function.
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Thorsten F??cking, Amtsgericht Hamburg HR B62 932