C++day3

[复制链接]
发表于 2024-6-9 13:20:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
头脑导图


  1. #include <iostream>
  2. using namespace std;
  3. class Person{
  4. private:
  5.     string name;
  6.     int age;
  7.     int *heigh;
  8.     int *weight;
  9. public:
  10.     Person(){
  11.         cout << "person::空参构造" << endl;
  12.     }
  13.     Person(string name, int age, int *heigh, int *weight):name(name), age(age), heigh(heigh), weight(weight){
  14.         cout << "person::含参构造" << endl;
  15.     }
  16.     ~Person(){
  17.         delete heigh;
  18.         delete weight;
  19.         cout << "person::析构函数" << endl;
  20.     }
  21. };
  22. class Student{
  23. private:
  24.     Person p;
  25.     double score;
  26. public:
  27.     Student(){
  28.         cout << "student::空参构造" << endl;
  29.     }
  30.     Student(string name, int age, int *heigh, int *weight, double score):p(name, age, heigh, weight), score(score){
  31.         cout << "student::含参构造" << endl;
  32.     }
  33.     ~Student(){
  34.         cout << "student::析构函数" << endl;
  35.     }
  36. };
  37. int main()
  38. {
  39.     int heigh = 180;
  40.     int weight = 70;
  41.     int *h = &heigh;
  42.     int *w = &weight;
  43.     Student s1();
  44.     Student s2("zhangsan", 23, h, w, 99.9);
  45.     return 0;
  46. }
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告
回复

使用道具 举报

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5

GMT+8, 2025-7-16 04:36 , Processed in 0.078236 second(s), 30 queries 手机版|qidao123.com技术社区-IT企服评测▪应用市场 ( 浙ICP备20004199 )|网站地图

快速回复 返回顶部 返回列表