1 先对于C做的扩展
1 结构体扩展
struct person{
char *name;
int age;
char *work;
void printInfo(void)
{
printf("name = %s, age = %d, work = %s\n",name,age,work);
}
};
int main(int argc, char **argv)
{
struct person persons[]={
{"zhangsan",10, "teacher"},
{"lisi", 15, "doctor"},
};
persons[0].printInfo();
persons[1].printInfo();
return 0;
}
2 类的引入
#include <stdio.h>
class person{
public:
char *name;
int age;
char *work;
void printInfo(void)
{
printf("name = %s, age = %d, work = %s\n",name,age,work);
}
};
int main(int argc, char **argv)
{
struct person persons[]={
{"zhangsan",10, "teacher"},
{"lisi", 15, "doctor"},
};
persons[0].printInfo();
persons[1].printInfo();
return 0;
}
第一课就结束了
网友评论