Environmental ubuntu 14.04
To write a small C ++ program, the definition of the structure when using a typedef struct structName {...}; result has prompted the expected unqualified-id before an error is prompted when members structName inside of this assignment error. In C ++, he said very clearly, when the definition of the structure typedef dispensable. So, for consistency with the c coding, I added typedef, and then thrown such a mistake. I do not understand. . .
Then later carefully checked and found that the original study of C / C ++ have forgotten the. My structure is defined as follows
typedef struct stack{
typedef struct link{
void * data;
link* next;
void initialize(void * data, link * next);
} * head;
void initialize();
void push(void * data);
void * peek();
void * pop();
void cleanup();
};
Access to some information first talk about the wrong place to write their own code.
typedef struct stack{
....
};
Equivalent in C ++ define struct stack {}; then using typedef struct stack stackAnotherName; Struct stack to the original definition of an alias called stackAnotherName. And my program at the end, and did not give an alias Struct stack, the equivalent of writing a line of code like typedef struct stack ;, so this place is wrong.
at this place
typedef struct link{
void * data;
link* next;
void initialize(void * data, link * next);
} * head;
In fact, like the ability to define a data structure of a link, and then use typedef struct link * head; that is to play a struct link * When an alias is called the head, so every time I refer to member variables in the head will be prompted expected unqualified -id before .....
The correct code should be like this, there is the head of my member variables defined. There is no problem.
typedef struct stack{
struct link{
void * data;
link* next;
void initialize(void * data, link * next);
} * head;
void initialize();
void push(void * data);
void * peek();
void * pop();
void cleanup();
}Stack;