C++学习第一课,笔记

2019-06-09  本文已影响0人  Mr小熊_1da7

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;

}


第一课就结束了

上一篇 下一篇

猜你喜欢

热点阅读