结构体用->出错

typedef struct DATA{
        char numeric[100];
  int  top;
 }Data;  
 Data data;
 data->top=-1;

编译出错:

Compiling...
crypt.cpp
E:\workspace\crypt\crypt.cpp(67) : error C2819: type 'calculate::DATA' does not have an overloaded member 'operator ->'
        E:\workspace\crypt\crypt.cpp(62) : see declaration of 'DATA'
E:\workspace\crypt\crypt.cpp(67) : error C2227: left of '->top' must point to class/struct/union
E:\workspace\crypt\crypt.cpp(74) : error C2819: type 'calculate::DATA' does not have an overloaded member 'operator ->'
        E:\workspace\crypt\crypt.cpp(62) : see declaration of 'DATA'
E:\workspace\crypt\crypt.cpp(74) : error C2227: left of '->top' must point to class/struct/union
执行 cl.exe 时出错.

crypt.exe - 1 error(s), 0 warning(s)

 

->只能用于只想结构体的指针变量,所以需定义:

 Data *data;

data=(Data*)malloc(sizeof(Data)); 

你可能感兴趣的:(结构体用->出错)