之前预期不合格的ID“ - >'令牌,如何解决这一问题? [英] expected unqualified-id before '->' token, How to fix this?

查看:624
本文介绍了之前预期不合格的ID“ - >'令牌,如何解决这一问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 结构框
{
    字符字[200] [200];
    字符的含义[200] [200];
    诠释计数;
};结构根{
    盒*字母[26];
};
结构根*茎;
结构盒*访问;
无效的init(){
    INT sizeofBox = sizeof的(结构盒);
    的for(int i = 0; I< = 25;我++){
        结构盒* TEMP =(结构盒*)(的malloc(sizeofBox));
        TEMP-GT&;计数= 0;
        根 - >字母[I] =温度; //错误行
    }
}


  

错误:之前的预期不合格的ID - >令牌


如何修复这个bug。
谁能解释一下什么样的是这样的... ??


解决方案

 根 - >字母[I] =温度;

下面是一个类型。它没有不准叫 - > 的一个类型。要使用这个操作符,你必须有一个指针,指向一个实例。

我觉得这条线应该是:

 茎>字母[I] =温度;
// ^^^^

但你会因为没有分配给它的内存这里有一个错误。

所以这行:

 结构根*茎;

应成为

 根*茎= / * ... * /; //关键词结构是不需要在这里C ++

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

How to fix this bug. Can anyone explain what kind is this...??

解决方案

root->alphabets[i] = temp;

Here root is a type. It no allowed to call -> on a type. To use this operator, you must have a pointer to an instance.

I think this line should be:

   stem->alphabets[i] = temp;
// ^^^^

But you will have an error here because there is no memory allocated for it.

So this line:

struct root *stem;

should become

root *stem = /* ... */; // keyword "struct" is not need here in c++

这篇关于之前预期不合格的ID“ - &GT;'令牌,如何解决这一问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆