ZBLOG

struct st_answer_trueOrfalse { bool banswer; bool banswer_standard; bool bret; }; struct st_answer_choose { int banswer; int banswer_standard; bool bret; }; struct st_answer_choose_multiple { QList banswer; ...

根据代码的描述,这样声明是没有问题的。然而,在C++中,结构体和联合体不能直接使用未命名的成员进行定义,需要在定义之前对其进行类型重命名。你可以将结构体和联合体分别重命名为 st_answer_trueOrfalsest_subject_Type,然后使用这些重命名后的类型进行声明。

以下是修改后的代码:

  1. struct st_answer_trueOrfalse {
  2. bool banswer;
  3. bool banswer_standard;
  4. bool bret;
  5. };
  6. struct st_answer_choose {
  7. int banswer;
  8. int banswer_standard;
  9. bool bret;
  10. };
  11. struct st_answer_choose_multiple {
  12. QList<QString> banswer;
  13. QList<QString> banswer_standard;
  14. bool bret;
  15. };
  16. typedef union {
  17. st_answer_trueOrfalse trueOrfalse;
  18. st_answer_choose choose;
  19. st_answer_choose_multiple choose_multiple;
  20. } st_subject_Type;
  21. struct st_subject {
  22. int subject_number;
  23. int subject_itype;
  24. QString subject_name;
  25. st_subject_Type subject_Type; // 使用重命名后的类型进行声明
  26. QImage image;
  27. int score;
  28. };
  29. st_subject subject; // 现在可以正常声明一个变量了

请注意,我还添加了头文件 QStringQImage 的引用,以确保代码能够成功编译和运行。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=18256

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?