Unconquerable p 2021-11-07 11:51 采纳率: 91.7%
浏览 23
已结题

#c++#报错下附代码以及目的,求解决

上代码:




#include <iostream>
#include <windows.h>
#include <string>
#include <cmath>

using namespace std; 
struct Student{
    string name;
    int age;
    string sex;
} ;
struct Teacher{
    string name;
    int age;
    string sex;
    int teachage;
};
struct defClass{
    string name;
    int grade;
    int cla;
    int wstudents;
    Student studentslist[wstudents];
    int teachers;
    Teacher techerslist[teachers];


};
int main(){
    
    defClass p;
    Student st1={"张三",12,"男"};
    Student st2={"李四",11,"男"};
    p.wstudents=2;
    p.studentslist{st1,st2};
    cout<<p.studentslist[1].age<<endl;
    return 0;
}

报错:

img


程序目的:声明defClass,Student,Teacher变量类型并创建defClass类,输出类中学生信息

  • 写回答

1条回答 默认 最新

  • [PE]经典八炮 2021-11-07 11:56
    关注
    p.studentslist{st1,st2};
    

    这是什么语法?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月18日
  • 已采纳回答 11月10日
  • 创建了问题 11月7日