typedef struct {
unsigned short int Position; // << That's what i'm trying to change!
unsigned short int OldPosition;
} Turn_s;
struct Turn_sMap{
Turn_s *Turn;
Turn_sMap *NextTurn;
};
New = new Turn_sMap;
New->Turn = new Turn_s;
New->Turn.Position = 0; // Already tried (New->Turn).Position = 0;
为什么我会收到编译错误?我是否没有访问结构 在结构内转动 New,而结构又有一个名为 Position 的成员?还是 typedef 会用一些指针疯狂来弄乱结构类型?请帮帮,我迷路了!):
声明
Turn_s *Turn;
使Turn
成为指针类型。若要访问成员对象,需要使用->
运算符。尝试:
New->Turn->Position = 0;
Turn_sMap::Turn
是一个指针。您需要取消引用它:
New->Turn->Position = 0;
此外,您不应该在C++中使用typedef struct
。只需声明结构:
struct Turn_s {
unsigned short int Position; // << That's what i'm trying to change!
unsigned short int OldPosition;
};
Turn_s a;
foo(a);