随笔分类 - <七>:C++对象优化
高级
摘要:move : 移动语义,得到右值类型 forward:类型转发,能够识别左值和右值类型 只有两种形式的引用,左值引用和右值引用,万能引用不是一种引用类型,它存在于模板的引用折叠情况,但是能够接受左值和右值 区分左值和右值得一个简单方式就是能不能取地址 一个右值一旦有名字那么就变成了左值 #inclu
阅读全文
摘要:#include <iostream> #include <cstring> class MyString { public: MyString(const char * _pname=nullptr) { if (_pname == nullptr) { pname = new char[1];
阅读全文
摘要:代码1 #include <iostream> #include <functional> #include<cstdio> #include<cstring> using namespace std; class MyString3 { public: MyString3(const char *
阅读全文
摘要:代码1 using namespace std; class TestV2 { public: TestV2(int a = 10) : ma(a) { cout << "TestV2(int) " << ma <<" 对象地址="<<this << endl; } ~TestV2() { cout
阅读全文
摘要:代码1 #include <iostream> using namepspace std; class Test { public: Test(int a=10):ma(a){cout<<"Test()"<<endl;} ~Test(){cout<<"~Test()"<<endl;} Test(co
阅读全文