Need enlightenment with this line of code
Was surfing and came across this line(supposed to be C) and I cant even make meaning of it.
|
int *(*foo[20]) (char *c);
|
please explain
Last edited on
It's an array of function pointer. The function has this signature:
1 2 3 4 5
|
int *f1(char *c)
{
cout << c;
return 0;
}
|
and is use like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
int main()
{
int *(*foo[20]) (char *c);
foo[0] = f1;
...
char x[] = "str";
int *res = (*foo[0])(x);
return 0;
}
|
Last edited on
haha :)
this syntax is a special beast in C++, and it's not the worst one...
ex: an array of pointers to member function:
1 2 3 4 5 6 7 8 9 10 11 12
|
struct foo
{
int* bar(char*) { return new int; };
};
void f()
{
int* (foo::*bar[20])(char*);
bar[0] = &foo::bar;
*(*(new foo).*bar[0])(new char('x')) = 100;
}
|
Last edited on
lol.....yeah
thanks. didnt see that one
Topic archived. No new replies allowed.