zhenhaowa66 发表于 2021-10-22 20:12:33

指针指向不完整的类类型

allocteSpace(struct Theacher*** teacherpArray) {

    struct Theacher** ts = malloc(sizeof(struct Teacher*) * 3);
    for (int i = 0; i < 3; i++) {
      ts= malloc(sizeof(struct Teacher));      // 下面的 ts 全部报错是怎么回事?
      ts->name = malloc(sizeof(char) * 32);
      sprintf(ts->name, "Teacher_%d", i + 1);

      ts->students = malloc(sizeof(char*) * 4);

      for (int j = 0; j < 4; j++) {
            ts->students = malloc(sizeof(char) * 32);
            sprintf(ts->students, "%s_students_%d", j + 1);
      }
    }

    *teacherpArray = ts;
}

第二个到第六个 ts 全部报错,说 不允许指针指向不完整的类类型“struct Theacher”
谁来帮帮忙,编译器是VS2019

zhenhaowa66 发表于 2021-10-22 20:17:50

代码是看视频抄来的,看视频老师用的是vs2013d的编译器,可以正常运行

zhenhaowa66 发表于 2021-10-22 20:51:01

已经找到问题了 {:5_109:}
页: [1]
查看完整版本: 指针指向不完整的类类型