欢迎光临散文网 会员登陆 & 注册

黑马程序员匠心之作|C++教程从0到1入门编程,学习编程不再难

2023-08-13 23:03 作者:您家水费超了  | 我要投稿
int tCount=1;
int sCount=1;
string aa(int *p);
struct Student{
   string name;
};
struct Teacher{
    string  name;
    Student student[3];
};
Teacher* creatTeacher(int tCount);

void bb(Student l);
void cc(Student *l);
int main() {
    Teacher *t[5];
    for (int i = 0; i <5 ; ++i) {
      t[i]= creatTeacher(tCount);
      cout <<t[i]->name<<endl;
        Student *s=&t[i]->student[0];
        for (int j = 0; j < size(t[i]->student) ; ++j) {
            cout <<s->name <<endl;
            s++;
        }
    }


}
Student createStudent(int count){
    Student s{"jeck"+to_string(count)};
    count++;
    return  s;
}
Teacher* creatTeacher(int tCount){
    Teacher* t = new Teacher{"Teacher" + to_string(tCount)};
    for (int i = 0; i < 3; ++i) {
        t->student[i] = createStudent(sCount);
        sCount++;
    }
    tCount++;
    return t;
}感觉我这种更灵活一点在拆分一下就是工厂,就是指针的传递有点恶心

黑马程序员匠心之作|C++教程从0到1入门编程,学习编程不再难的评论 (共 条)

分享到微博请遵守国家法律