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,然后使用这些重命名后的类型进行声明。

以下是修改后的代码:

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<QString> banswer;
    QList<QString> banswer_standard;
    bool bret;
};

typedef union {
    st_answer_trueOrfalse trueOrfalse;
    st_answer_choose choose;
    st_answer_choose_multiple choose_multiple;
} st_subject_Type;

struct st_subject {
  int subject_number;
  int subject_itype;
  QString subject_name;
  st_subject_Type subject_Type; // 使用重命名后的类型进行声明
  QImage image;
  int score;

};

st_subject subject; // 现在可以正常声明一个变量了

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


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

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

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?