| Profil von Yi JunS_A's SpaceFotosBlogListen | Hilfe |
C++ PuzzleIt's a valid declaration: Char (*(*x())[]) ().
I've been in confused for a long time. >_<
Let's see the following code segement:
#include <iostream>
using namespace std;
char retChar() { return 'A'; }
char (*(*x())[1])() {
char (*q[])() = { &retChar };
char (*(*p)[1])() = &q;
return p;
} void main() { cout << (*(x()))[0](); }
The output is 'A'.
char (*(*x())[1])() is a function declaration,
whose return value is a pointer,
which points to an array of function pointers,
and the function returns char.
(^^ Thanks for Ji Cheng's help.)
It seems that we get the answer finally.
But char (*(*x())[])() and char (*(*x())[1])() are different.
If we remove the '1' in the above code segement, it will appear:
cannot convert from 'char (__cdecl *(*)[1])(void)' to 'char (__cdecl *(*)[])(void)'
Now we know what is char (*(*x())[num])(),
but what is Char (*(*x())[]) ()? Kommentare (9)Melden Sie sich zum Hinzufügen eines Kommentars mit Ihrer Windows Live ID an (wenn Sie Hotmail, Messenger oder Xbox LIVE verwenden, besitzen Sie eine Windows Live ID). Anmelden Sie haben noch keine Windows Live ID? Registrieren
TrackbacksDie Trackback-URL für diesen Eintrag ist: http://un-real.spaces.live.com/blog/cns!932D37462BC0B64F!872.trak Weblogs, die sich auf diesen Eintrag beziehen
|
|
|