C++对象缺省函数
来源:互联网 发布:淘宝店铺运营分析报告 编辑:程序博客网 时间:2024/06/14 13:11
#include <iostream>
#include <string>
using namespace std;
class CTestPlus{
public:
CTestPlus(){
m =0;
p=new int(100);
}
~CTestPlus(){delete p;}
CTestPlus(const CTestPlus& a) //拷贝构造函数
{
m = a.m;
p = new int;
*p = *(a.p);
}
CTestPlus& operator=(const CTestPlus& a) //赋值函数
{
m = a.m;
p = new int;
*p = *(a.p);
return *this;
}
void output(CTestPlus &a)
{
cout<<"a.m ="<<a.m<<endl;
cout<<"a.p ="<<*(a.p)<<endl;
}
private:
int m;
int *p;
#include <string>
using namespace std;
class CTestPlus{
public:
CTestPlus(){
m =0;
p=new int(100);
}
~CTestPlus(){delete p;}
CTestPlus(const CTestPlus& a) //拷贝构造函数
{
m = a.m;
p = new int;
*p = *(a.p);
}
CTestPlus& operator=(const CTestPlus& a) //赋值函数
{
m = a.m;
p = new int;
*p = *(a.p);
return *this;
}
void output(CTestPlus &a)
{
cout<<"a.m ="<<a.m<<endl;
cout<<"a.p ="<<*(a.p)<<endl;
}
private:
int m;
int *p;
};
#include "CTestPlus.h"
int main()
{
CTestPlus ctest;
CTestPlus A = ctest;
ctest.output(A);
//cout<<"A.m ="<<A.m;
CTestPlus c;
c =A;
ctest.output(c);
int wait;
cin>>wait;
}
0 0
- C++对象缺省函数
- More Effective C++:避免缺省构造函数
- 缺省函数
- C++【函数(重载/缺省参数/哑元/内联)】
- 缺省构造函数
- 缺省构造函数
- 关于缺省构造函数
- 函数的缺省参数
- 函数缺省是external
- 函数的缺省参数
- 函数的缺省参数
- c++函数缺省参数
- Cpp_函数缺省参数
- 缺省构造函数
- 函数的缺省参数
- c++ 函数缺省参数
- 构造缺省函数
- C++ 函数缺省参数
- 前缀 后缀 中缀 表达式
- aliasing demo(binding, reference)
- leetcode-190&191 Reverse Bits & Number of 1 Bits
- Java基础之工厂模式的思考
- 虚函数的使用
- C++对象缺省函数
- 树的前序,中序,后序推理问题
- dede 开源 中文分词 可用于 ecshop
- C#《猜猜看》游戏开发总结
- Java IO流详解
- Eclipse workspace error
- Sublime Text中使用正则表达式删除空行
- 做一个机智的胖老鼠(贪心)
- Hadoop2.6.0 mac 安装