我不理解为什么下面的声明是被接受的:
typedef void (*_tStandardDeclaration)(LPVOID);
而以下内容则不行:
typedef void *_tDeclarationWithoutParenthesis(LPVOID);
typedef void* _tAlternateDeclaration(LPVOID);
我正在使用MSVC6(我知道它已经过时且非标准,但为了维护每年数百万的收入系统而需要:/)
我不理解为什么下面的声明是被接受的:
typedef void (*_tStandardDeclaration)(LPVOID);
而以下内容则不行:
typedef void *_tDeclarationWithoutParenthesis(LPVOID);
typedef void* _tAlternateDeclaration(LPVOID);
我正在使用MSVC6(我知道它已经过时且非标准,但为了维护每年数百万的收入系统而需要:/)
指针符号默认绑定到类型,因此函数指针需要括号来表示指针实际上是在名称上而不是在返回类型上。
如果没有使用括号,那么你声明的是一个返回 void*
的函数,而不是指向返回 void
的函数的指针。
c++ -Wall -Wextra -c xx.cpp
代码:
typedef void *LPVOID;
typedef void (*_tStandardDeclaration)(LPVOID);
typedef void *_tDeclarationWithoutParenthesis(LPVOID);
typedef void* _tAlternateDeclaration(LPVOID);
第一个指向返回void
的函数的指针;后两个是等效的(间距没有影响),它们给出了一种类型,即“接受LPVOID参数并返回指向void的指针的函数”。
您可以使用它们来声明函数指针:
typedef _tDeclarationWithoutParenthesis *_tFunctionPointer;
Fun, isn't it...