C++ std::bind思考
来源:互联网 发布:炉石传说mac版2017 编辑:程序博客网 时间:2024/05/16 18:19
class test_rcp{public:test_rcp();~test_rcp();test_rcp(const test_rcp& c){m_i = c.m_i;}public:void testrpc_1(){cout << "in testrpc_1\t" << m_i<<endl;}public:int m_i;};test_rcp::test_rcp(){m_i = 200;}test_rcp::~test_rcp(){}int main(){test_rcp* testrpc = new test_rcp; //auto f = std::bind(&test_rcp::testrpc_1, *testrpc);auto f = std::bind(&test_rcp::testrpc_1, testrpc);testrpc->m_i+=1;//delete testrpc;f();cin.get();return 0;}
1.当std::bind绑定的是对象,会触发 test_rcp(const test_rcp& c) 拷贝构造函数,且输出的结果为:in testrpc_1 200
说明存入对象std::bind会对对象就行拷贝
2.当std::bind绑定的是对象的指针,并不会触发 test_rcp(const test_rcp& c) 拷贝构造函数,且输出的结果:in testrpc_1 201
说明绑定对象指针时,只是单纯的复制对象指针
3.在调用std::bind绑定函数之前delete testrpc,传递指针的情况下m_i的值不规律,因为该指针指向的地址已经被释放了,该调用引用了非法的内存地址
4.在对象已经被析构的情况下std::bind是怎么做到还能成功调用对象的成员函数的呢?这点不太懂
0 0
- C++ std::bind思考
- C++-----------------------------------------------------std::bind
- C++_std::bind std::function 高级用法
- 关于std::bind绑定栈变量对象的思考
- std::bind绑定器、std::function、extern C的使用
- std::bind
- std::bind
- std::bind
- std::bind
- std::bind
- std::bind
- std::bind
- std::function std::bind
- std::function std::bind
- 【C/C++】C++11新特性:std::bind
- C++11 学习笔记 std::function和bind绑定器
- C++11 笔记 std::function,bind绑定器和lambda
- std::function 和 std::bind
- 计算机视觉、机器学习相关领域论文和源代码大集合--持续更新……
- C#编程基础 实验(10) (5)
- MaterialDesign之Dialog
- instr like
- Search in Rotated Sorted Array-旋转数组的查找
- C++ std::bind思考
- c++ curl下载和上传数据——c++(学习一)
- Android签名简介
- STL
- Eclipse引用外部project android library
- Linux make
- iOS dispatch_group的使用
- 解决zlib.h:no such file or directory
- windows上安装eclipse