c/c++语言开发共享在’ – >’标记之前预期的unqualified-id,如何解决这个问题?

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 ; icount = 0; root->alphabets[i] = temp; //error line } } 

错误:在’ – >’标记之前预期的unqualified-id

如何解决这个bug。 谁能解释一下这是什么类型的?

     root->alphabets[i] = temp; 

    这里的root是一种类型。 它不允许在类型上调用-> 。 要使用此运算符,您必须具有指向实例的指针。

    我认为这一行应该是:

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

    但是你会在这里遇到错误,因为没有为它分配内存。

    所以这一行:

     struct root *stem; 

    应该成为

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

    root是一种类型。 你不能在一个类型上调用operator -> 。 您需要一个指向实例的指针(或一个重载类型的实例-> )。 你不需要在c ++中的所有地方编写struct

     root* smth = ....; // look, no "struct" smth->alphabets[0] = ....; 

    请注意,在C ++代码中广泛使用原始指针并不是惯用的。 修复此问题后,您将遇到其他问题。

      以上就是c/c++开发分享在’ – >’标记之前预期的unqualified-id,如何解决这个问题?相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/519168.html

      (0)
      上一篇 2020年12月5日
      下一篇 2020年12月5日

      精彩推荐