我有一个类:
class systemcall
{
typedef struct
{
int pid;
int fptrCntr;
OpenFile openfileptrs[10];
}processTable[100];
public:
//other stuff...
}
我有一个成员函数
/* this function initializes the process table. */
void systemcall::initpTable()
{
int i = 0;
for ( i=0; i<100; i++ ) {
processTable[i].fptrCntr = 0;
}
}
processTable[i].fptrCntr = 0;
行给出错误:
systemcall.cc:86: error: expected unqualified-id before '[' token
我的头发都快拔光了!!!任何想法为什么会这样?我什至把结构放在 systemcall.cc 文件中,但没有用。
谢谢。
最佳答案
您不希望在 processTable
声明之前使用 typedef
,因为您声明的是对象,而不是类型。将 processTable
定义为类型后,您可以继续将其用作成员对象,这会使编译器感到困惑。
关于c++ - 如何在类中定义结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5394342/