五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
浪卡子县| 固原市| 仙桃市| 柯坪县| 苏尼特右旗| 年辖:市辖区| 肥乡县| 平度市| 咸宁市| 塘沽区| 东光县| 伽师县| 错那县| 乐亭县| 黄龙县| 固阳县| 英山县| 黄梅县| 清水河县| 惠州市| 大城县| 汤阴县| 双柏县| 蒙城县| 布尔津县| 台南市| 大埔县| 宁城县| 平舆县| 报价| 墨脱县| 吉林市| 波密县| 西畴县| 安徽省| 梧州市| 铁岭县| 兖州市| 刚察县| 永清县| 赤城县|