国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

enable_shared_from_this

2023-02-24 02:28 作者:小粉絲8  | 我要投稿

// https://learn.microsoft.com/en-us/cpp/standard-library/enable-shared-from-this-class?view=msvc-170

#include <memory>

#include <iostream>

#include <cstring>

using namespace std;

struct base

? ? // : public std::enable_shared_from_this<base>

{

? ? char *val;

? ? base(){

? ? ? ? val = new char[1024];

? ? }

? ? ~base(){

? ? ? ? delete []val;

? ? }

? ? // shared_ptr<base> share_more()

? ? base *share_more()

? ? {

? ? ? ? // return shared_from_this();

? ? ? ? return this;

? ? }

};

int main2()

{

? ? // std::shared_ptr<base> sp2;

? ? base *sp2;

? ? {

? ? ? ? // std::shared_ptr<base> sp1 = make_shared<base>();

? ? ? ? base b; base *sp1 = &b;

? ? ? ? sp2 = sp1->share_more();

? ? ? ? std::strncpy(sp1->val, "hello", 1024 - 1);

? ? }

? ? cout << "sp2->val == " << sp2->val << endl;

? ? return 0;

}

---

// https://learn.microsoft.com/en-us/cpp/standard-library/enable-shared-from-this-class?view=msvc-170

#include <memory>

#include <iostream>

#include <cstring>

using namespace std;

struct base

? ? : public std::enable_shared_from_this<base>

{

? ? char *val;

? ? base(){

? ? ? ? val = new char[1024];

? ? }

? ? ~base(){

? ? ? ? delete []val;

? ? }

? ? shared_ptr<base> share_more()

? ? // base *share_more()

? ? {

? ? ? ? return shared_from_this();

? ? ? ? // return this;

? ? }

};

int main3()

{

? ? std::shared_ptr<base> sp2;

? ? // base *sp2;

? ? {

? ? ? ? std::shared_ptr<base> sp1 = make_shared<base>();

? ? ? ? // base b; base *sp1 = &b;

? ? ? ? sp2 = sp1->share_more();

? ? ? ? std::strncpy(sp1->val, "hello", 1024 - 1);

? ? }

? ? cout << "sp2->val == " << sp2->val << endl;

? ? return 0;

}


enable_shared_from_this的評論 (共 條)

分享到微博請遵守國家法律
诸暨市| 新蔡县| 华阴市| 卢龙县| 马龙县| 永春县| 义乌市| 元朗区| 青州市| 祥云县| 友谊县| 钦州市| 柳林县| 兰考县| 罗平县| 昆山市| 济源市| 贡觉县| 彩票| 厦门市| 隆昌县| 河曲县| 灵宝市| 吴旗县| 娱乐| 阿鲁科尔沁旗| 西和县| 罗城| 花莲县| 景宁| 锡林郭勒盟| 南城县| 惠来县| 惠水县| 镇安县| 肃宁县| 大石桥市| 嫩江县| 河北区| 宜川县| 麟游县|