【发布时间】:2011-05-28 10:06:01
【问题描述】:
我正在用 C 语言编程。 考虑以下代码。
我的结构定义为:
// Define the stack
struct stackNode {
char data;
struct stackNode *nextPtr;
};
typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;
使用了以下变量:
StackNode topTracker; // The pointer of this stackNode will always point to the top of the stack
我正在尝试完成以下功能。
char pop( StackNodePtr *topPtr ){
char returnable;
// store the Node.data from the top of the stack
returnable = *topPtr.data; //[1]
// Set the next Node to the top of the stack
topTracker.nextPtr = *topPtr.nextPtr; //[2]
// return the Node data.
return returnable;
问题是我收到以下错误:分别在点 [1] 和 [2]
“在非结构或联合的情况下请求成员 data' in something not a structure or union"
"request for membernextPtr'”
如何绕过这个错误并实际访问指针 *topPtr 的数据和 nextPtr?假设 *topPtr 在运行时将是一个指向实际 StackNode 的指针。
【问题讨论】: