c++拷贝构造函数(对比于上一篇)
来源:互联网 发布:软件开发技术发展方向 编辑:程序博客网 时间:2024/05/17 22:41
#include <fstream>#include <string>using namespace std;ofstream out("HowMany.out");class HowMany {string name; static int objectCount;public:HowMany(const string str=""):name(str) { objectCount++; }HowMany( HowMany& X){name=X.name+"COPY";objectCount++; out<<name<<endl;} static void print(const string& msg = "") { if(msg.size() != 0) out << msg << ": "; out << "objectCount = " << objectCount << endl; } ~HowMany() { objectCount--; print("~HowMany()"); }};int HowMany::objectCount = 0;// Pass and return BY VALUE:HowMany f(HowMany x) { x.print("x argument inside f()"); return x;}int main() { HowMany h("h"); HowMany::print("after construction of h"); HowMany h2("h2"); out<<"test1........"<<endl; h2=f(h); out<<"test2........"<<endl; HowMany::print("after call to f()");} ///:~
输出结果为
after construction of h: objectCount = 1
test1........
hCOPY
x argument inside f(): objectCount = 3
hCOPYCOPY
~HowMany(): objectCount = 3
~HowMany(): objectCount = 2
test2........
after call to f(): objectCount = 2
~HowMany(): objectCount = 1
~HowMany(): objectCount = 0
- c++拷贝构造函数(对比于上一篇)
- 拷贝构造函数(C++)
- 拷贝构造函数(C++)
- c++(拷贝构造函数)
- 【C++】拷贝构造函数
- C++:拷贝构造函数
- c++"拷贝构造函数
- C++: 拷贝构造函数
- 【C++】拷贝构造函数
- c++::拷贝构造函数
- 【C++】:拷贝构造函数
- 【C++】拷贝构造函数
- C++:拷贝构造函数
- c++-拷贝构造函数(复制构造函数)
- 混迹于C++之拷贝赋值函数和拷贝构造函数(一)
- 混迹于C++之拷贝赋值函数和拷贝构造函数(二)
- 混迹于C++之拷贝赋值函数和拷贝构造函数(三)
- 一篇关于拷贝构造函数的争论
- 云计算与OpenStack(虚拟机Nova篇)
- uva 147 Dollars (dp + 完全背包)
- 实体类如何与算法实现松耦合
- 关于使用Eclipse编辑Android程序出现R文件消失的问题
- Storm的Zookeeper启动报错
- c++拷贝构造函数(对比于上一篇)
- 计算机和控制领域SCI收录期刊及其影响因子
- Android使用系统Intent实现分享功能及将应用加入分享列表
- bullet学习初步思路
- java.io.EOFException解决
- ThinkPHP U方法
- JSON数据解析(GSON方式)
- 正则应用之——日期正则表达式
- 0欧姆电阻 电感与磁珠的选择