1
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;

为什么我得到那个编译错误?我没有访问 struct New 中的 struct Turn,它又具有一个名为 Position 的成员吗?或者 typedef 是否会用一些指针疯狂来混淆结构类型?请帮忙,我迷路了!):

4

2 回答 2

2

该声明Turn_s *Turn;创建了Turn一个指针类型。要访问成员对象,您需要使用->运算符。尝试:

New->Turn->Position = 0;
于 2012-06-10T01:50:46.233 回答
1

Turn_sMap::Turn是一个指针。您需要取消引用它:

New->Turn->Position = 0; 

此外,您不应该typedef struct在 C++ 中使用。只需声明结构:

struct Turn_s {
    unsigned short int Position; // << That's what i'm trying to change!
    unsigned short int OldPosition;
};

Turn_s a;
foo(a);
于 2012-06-10T01:50:03.900 回答