11.30 C++类特殊成员函数

news/2024/7/5 10:13:50

#include <iostream>

using namespace std;
class Per
{
private:
    string name;
    int age;
    double *high;
    double weight;
public:
    //构造函数
    Per(string name,int age,double high,double weight):name(name),age(age),high(new double(high)),weight(weight)
    {
        cout << "Per::构造函数" << endl;
    }
    //拷贝构造函数
    Per(const Per &other):name(other.name),age(other.age),high(new double(*(other.high))),weight(other.weight)
    {
        cout << "Per::拷贝构造函数" << endl;
    }
    //析构函数
    ~Per()
    {
        delete high;
        cout << "Per::析构函数" << endl;
    }
};
class Stu
{
private:
    double score;
    Per p1;
public:
    Stu(double score,string name,int age,double high,double weight):score(score),p1(name,age,high,weight)
    {
        cout << "Stu::构造函数" << endl;
    }
    Stu(const Stu &other):score(other.score),p1(other.p1)
    {
        cout << "Stu::拷贝构造函数" << endl;
    }
    ~Stu()
    {
        cout << "Stu::析构函数" << endl;
    }
};
int main()
{
    Per p1("张三",18,185,80);
    Per p2(p1);
    cout << "++++++++++++++++++++++++++++++++++++" << endl;
    Stu s1(99,"李四",20,175,60);
    Stu s2(s1);
    cout << "++++++++++++++++++++++++++++++++++++" << endl;
    return 0;
}


http://lihuaxi.xjx100.cn/news/1852390.html

相关文章

ant design vue3 处理 ant-card-head ant-tabs靠左边对齐之has选择器不生效

火狐浏览器是不支持has的。 解决方法&#xff1a;通过position来解决。

航城街道携股份公司一行莅临联诚发考察调研

11月30日&#xff0c;深圳市宝安区航城街道组织开展主题为“交流促发展携手创未来”的调研服务日活动。当日上午&#xff0c;航城街道委员刘甜携集体资产监管办、黄田股份合作公司、钟屋股份合作公司、草围股份合作公司、鹤洲股份合作公司、九围股份合作公司、后瑞股份合作公司…

达梦数据库安装(DM8)新版 windows11下安装及超详细使用教程

达梦数据库安装&#xff08;DM8&#xff09;新版 windows11下安装及超详细使用教程 新电脑安装重新写了一下 注意看一下踩坑部分 文章目录 1.DM 数据库安装1.1 windows11安装前准备1.1.0 安装环境要求1.1.1 检查系统信息1.1.2 检查系统内存1.1.3 检查存储空间 1.2 官网下载免…

编译企业微信会话内容存档PHP版SDK扩展

1.下载SDK 如果克隆不了&#xff0c;就页面下载 git clone https://github.com/pangdahua/php7-wxwork-finance-sdk2.下载企微官网C版本的最新sdk文件 下载地址&#xff1a;https://wwcdn.weixin.qq.com/node/wework/images/sdk_20201116.rar 下载以后将解压之后的文件夹里l…

python国内下载网站

https://mirrors.huaweicloud.com/python/

11-30例题-python

50. Pow(x, n) class Solution(object):def myPow(self, x, n):""":type x: float:type n: int:rtype: float"""# 终止条件if n0:return 1# 三种情况# n<0 n的-x分之一if n<0:x1/xn-n# x是奇数 x*x的偶数次方if n%2:return x *self.myPow…

第16关 革新云计算:如何利用弹性容器与托管K8S实现极速服务POD扩缩容

------> 课程视频同步分享在今日头条和B站 天下武功&#xff0c;唯快不破&#xff01; 大家好&#xff0c;我是博哥爱运维。这节课给大家讲下云平台的弹性容器实例怎么结合其托管K8S&#xff0c;使用混合服务架构&#xff0c;带来极致扩缩容快感。 下面是全球主流云平台弹…

C语言中的预处理指令

预处理指令是在编译之前由预处理器处理的命令。这些指令不是C语言的一部分,而是指导预处理器如何准备代码进行编译。预处理指令以井号(#)开头,主要可以分为以下几组: 一、 宏定义指令 #define: 定义宏。 #undef: 取消已定义的宏。宏可以定义常量,如 #define PI 3.14159。…