// ============================================================================ // p1c04_01_01 — 4.1.2 类的封装 // 来源:川大 C++/LinuxC wiki「02.Qt方向」 // 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用 // // --- 原文片段 [pageId:blockIdx] --- 标注出处。 // 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。 // ============================================================================ #include #include #include // --- 原文片段 [58954448:0] 4.1.2 类的封装 --- typedef struct _Person{ char name[64]; int age; }Person; typedef struct _Aninal{ char name[64]; int age; int type; //动物种类 }Ainmal; void PersonEat(Person* person){ printf("%s在吃人吃的饭!\n",person->name); } void AnimalEat(Ainmal* animal){ printf("%s在吃动物吃的饭!\n", animal->name); } int main(){ Person person; strcpy(person.name, "小明"); person.age = 30; AnimalEat(&person); return EXIT_SUCCESS; } // --- main ---