从逆向分析角度看C++拷贝构造函数
作者:网络转载 发布时间:[ 2013/3/19 10:28:35 ] 推荐标签:
进入f()函数后
*********************************************************
再看<<Thinking in C++>>中的一段代码,更为清晰的讲解了拷贝构造函数的机制:
//: HowMany_2.cpp
#include <string>
#include <iostream>
using namespace std;
class HowMany {
string name;
static int objectCount;
public:
HowMany(const string& id = "") {
name = id;
++objectCount;
print("HowMany()");
}
~HowMany() {
--objectCount;
print("~HowMany()");
}
HowMany(const HowMany& h) {
name = h.name + "copy";
++objectCount;
print("HowMany(const HowMany&)");
}
void print(const string& msg = "") {
if (msg.length() != 0) {
cout << msg << endl;
}
cout << ' ' << name << ": "
<< "objectCount = " << objectCount << endl;
return ;
}
};
int HowMany::objectCount = 0;
HowMany f(HowMany x) {
x.print("x argument inside f()");
cout << "Return From f()" << endl;
return x;
}
int main() {
{
HowMany h("h");
cout << "Entering f()" << endl;
HowMany h2 = f(h);
cout << "Call f(), no return value" << endl;
f(h);
cout << "After call to f()" << endl;
}
// getchar();
return 0;
} ///:~
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11