gpt4 book ai didi

c++ - 包含它的模板化类型的 shared_ptr

转载 作者:行者123 更新时间:2023-11-28 04:32:26 36 4
gpt4 key购买 nike

是否可以让 shared_ptr 指向包含它的模板类型?例如,

pair<shared_ptr<ThisPairType>, int>

这应该如何定义?

最佳答案

不可能直接写你想要的,因为在你想使用它的时候类型的名称还没有完成。你甚至不能用 typedef 来解决这个问题因为不可能转发声明 typedef。

我建议简单地写一个结构:

struct Recursive { std::shared_ptr<Recursive> first; int second; };

或者继承自pair根据 igor's 的推荐评论:

The best I could think of is struct ThisPairType : std::pair<std::shared_ptr<ThisPairType>, int> {}; Which is not quite what you want, but close.

关于c++ - 包含它的模板化类型的 shared_ptr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52509690/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com