struct box
{
char word[200][200];
char meaning[200][200];
int count;
};
struct root {
box *alphabets[26];
};
struct root *stem;
struct box *access;
void init(){
int sizeofBox = sizeof(struct box);
for(int i = 0 ; i<= 25; i++){
struct box *temp =(struct box*)( malloc(sizeofBox));
temp->count = 0;
root->alphabets[i] = temp; //error line
}
}
Error: Expected unqualified-id before '->' token
如何修复这个错误。 谁能解释一下这是什么...??
最佳答案
root->alphabets[i] = temp;
这里root
是一种类型。不允许在类型上调用 ->
。要使用此运算符,您必须有一个指向实例的指针。
我认为这一行应该是:
stem->alphabets[i] = temp;
// ^^^^
但是这里会出现错误,因为没有为其分配内存。
所以这一行:
struct root *stem;
应该变成
root *stem = /* ... */; // keyword "struct" is not need here in c++
关于c++ - '->' token 之前预期有不合格的 id,如何解决此问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18799680/