首页 > 编程语言 > 详细

C++基础知识_class是对struct的扩展

时间:2019-12-10 23:34:03      阅读:110      评论:0      收藏:0      [点我收藏+]

使用结构体:

技术分享图片
 1 #include <stdio.h>
 2 
 3 struct person
 4 {
 5     char *name;
 6     int age;
 7     char *work;
 8     void (*printInfo)(struct person *per);//函数指针
 9 };
10 
11 void printInfo(struct person *per)
12 {
13     printf("%s,%d,%s\n",per ->name,per ->age,per ->work);
14 }
15     
16 
17 int main(int argv,char **argc)
18 {
19     struct person persons[] = {{"zhangsan",10,"teacher",printInfo},{"lisi",20,"doctor",printInfo}};
20     persons[0].printInfo(&persons[0]);
21     persons[1].printInfo(&persons[1]);
22     
23 }
View Code

 

C++基础知识_class是对struct的扩展

原文:https://www.cnblogs.com/yekongdebeijixing/p/12019621.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!