杂七杂八
来源:互联网 发布:调整优化作战力量结构 编辑:程序博客网 时间:2024/09/21 11:20
#include <iostream>using namespace std;class TestClass{friend ostream& operator<<(ostream&, TestClass&);public:TestClass(int *ptr) :p(ptr){}TestClass(const TestClass &value) : p(new int(*(value.p))) {}TestClass(TestClass &&value) :p(value.p) { value.p = nullptr; }TestClass& operator=(const TestClass& value){TestClass tmp(value);swap(tmp);cout << "copy" << endl;return *this;}TestClass& operator=(TestClass &&value){if (this != &value){delete p;p = value.p;value.p = nullptr;}cout << "move" << endl;return *this;}void swap(TestClass& other){using std::swap;swap(p, other.p);}private:int *p;};ostream& operator<<(ostream& os, TestClass& value){os << *(value.p);return os;}void swap(TestClass& a, TestClass& b){a.swap(b);}TestClass func(TestClass parameter){return parameter;}int main(){TestClass demo_1(new int(1));TestClass demo_2(new int(2));demo_1 = std::move(demo_2);//demo_1 = demo_2;cout << demo_1 << endl;demo_2 = func(new int(3));cout << demo_2 << endl;return 0;}
0 0
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 杂七杂八
- 线程组
- [Linux]Bash中的任务(job)管理
- 第十周项目四大奖赛计分(3)
- fingergame_猜拳小游戏
- js实现搜索框提示字的特效------------获取焦点和失去焦点
- 杂七杂八
- PR 审批界面增加显示项方法
- Android JNI 开发之NDK环境配置
- Git教程【译】
- JavaScript(7) 继承
- 第十周项目6 陌生人和百万富翁做交易
- STM32 SysTick 精准延时 简单分析
- Linux 升级Python
- 交叉编译工具链