[英]LPBYTE Macro Generates Error at Compile - C++
I have the following code that is generating an error when I try to build the application: 我有以下代码,在尝试构建应用程序时会产生错误:
#define LPAFDU LPBYTE;
typedef struct appAfDataIndIeee_tag
{
integrPktHead_t head;
BYTE flags;
WORD dstShort;
BYTE dstEndpoint;
BYTE srcShort;
BYTE srcIeee[8];
WORD clusterId;
BYTE afduLength;
LPAFDU afdu; // <-- error
} appAfDataIndIeee_t;
This is the error it generates: 这是它生成的错误:
error C2208: 'BYTE *' : no members defined using this type
错误C2208:“ BYTE *”:没有使用此类型定义的成员
error C4430: missing type specifier - int assumed.错误C4430:缺少类型说明符-假定为int。 Note: C++ does not support default-int
注意:C ++不支持default-int
If I switch out LPADFU
for LPBYTE
it compiles successfully. 如果我将
LPADFU
LPBYTE
则编译成功。 I would prefer to use a define or type-definition of LPADFU
. 我更喜欢使用
LPADFU
的定义或类型定义。 Does anyone know how I can make this work? 有谁知道我该怎么做? Thanks.
谢谢。
Get rid of the semicolon at the end of your #define
(it's part of the macro): 在
#define
的末尾消除分号(它是宏的一部分):
#define LPAFDU LPBYTE
A far better way to do this, however, is to use typedef
rather than #define
: 但是,更好的方法是使用
typedef
而不是#define
:
typedef LPBYTE LPAFDU;
The most important advantage of typedefs is that they obey scope rules. typedef的最重要的优点是它们遵守范围规则。
Remove the semicolon from your declaration of LPAFDU. 从LPAFDU声明中删除分号。
#define LPAFDU LPBYTE
You're probably thinking of a typedef statement, which would have a semicolon. 您可能正在考虑使用typedef语句,该语句将使用分号。 With
#define
, the definition is inserted wherever the macro is, including your semicolon. 使用
#define
,可以在宏所在的位置(包括分号)插入定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.