auto-ptr

auto-ptr

文章 0 浏览 6

提供“安全”的环境。与 auto_ptr 一起使用的 push() 函数

我想声明一个“安全”的 push() 函数,与 auto_ptr 一起使用,如下所示: template inline void push( StackType &s, auto_ptr p ) { s.push( p.get()…

零時差 2024-11-08 16:28:30 13 0

删除 boost::bind 的原始指针参数

假设我已经分配了堆A*,我想将其作为参数传递给boost::bind。 boost::bind 被保存在一些 STL 中(例如 boost::functions 的容器)以便以后处理。 我想…

煮茶煮酒煮时光 2024-11-06 20:02:35 12 0

删除指向不完整类型和智能指针的指针

当尝试使用带有前向声明的类型的 auto_ptr 时,如下所示: class A; ... std::auto_ptr a; A 的析构函数未被调用(显然,因为 auto_ptr 内部删除底层…

孤檠 2024-10-31 11:59:06 12 0

为什么 std::auto_ptr 上不允许使用运算符 []

为什么 std::auto_ptr 上不允许使用运算符 []? #include using namespace std ; template void foo( T capacity ) { auto_ptr temp = new T[capacity…

柠檬色的秋千 2024-10-24 08:57:22 17 0

使用 C++ 将指针传递给 auto_ptr

我有一个函数可以执行此操作: static MyClass* MyFunction(myparams) { return new MyClass(myparams) } 并且我可以在另一个具有以下签名的函数中调…

东风软 2024-10-17 00:31:49 12 0

放弃 auto_ptr

有时候,在转瞬即逝的时刻,我认为 auto_ptr 很酷。但大多数时候我认识到有一些更简单的技术使它变得无关紧要。例如,如果我想自动释放一个对象,即使…

橘虞初梦 2024-10-14 21:52:55 16 0

将shared_ptr转换为auto_ptr?

我需要在代码中从shared_ptr 获取auto_ptr。我可以进行反向操作 - 将 auto_ptr 转换为共享指针,因为共享指针具有这样的构造函数: template explicit…

烟─花易冷 2024-10-13 07:42:01 18 0

像 std::vector 这样的容器中的智能指针?

我正在学习智能指针 (std::auto_ptr),只需阅读此处 和此处 智能指针 (std::auto_ptr )不应放入容器(即std::vector)中,因为即使大多数编译器也不…

等待我真够勒 2024-10-09 16:17:04 17 0

对容器对象的子集的引用

我有一个关于引用集合子集的快速问题。 考虑我有一个对象向量。现在我想创建另一个向量,它是该向量的子集,并且我不想创建对象子集的副本。 我正在考…

你与清晨阳光 2024-10-08 19:23:42 11 0

C++ std::auto_ptr 复制构造函数

std::auto_ptr 缺少 const 复制构造函数,因此我无法直接在集合中使用它。有没有办法在不使用 boost 指针集合模板的情况下获得例如 std::auto_ptr 向…

喵星人汪星人 2024-09-28 08:20:40 11 0

指针和智能指针的区别

你能告诉我这段代码有什么问题吗?我在一次采访中被问到这个问题,我不确定 tClass 是一个测试类,它的方法 printSomething 可以打印 tClass 的成员。…

筱果果 2024-09-26 02:27:15 8 0

为什么 auto_ptr 被弃用?

我听说 auto_ptr 在 C++11 中已被弃用。这是什么原因呢? 我还想知道 auto_ptr 和 shared_ptr 之间的区别。…

止于盛夏 2024-09-18 15:43:53 17 0

auto_ptr 陷阱和陷阱

除了使用 auto_ptr 的所有已知好处之外,auto_ptr “最差做法”是什么? 创建 auto_ptrs 的 STL 容器。 auto_ptrs 不满足“CopyConstructable”要求。…

疏忽 2024-09-16 22:08:29 10 0

std::auto_ptr 到 std::unique_ptr

随着新标准的到来(以及某些编译器中已经可用的部分),新类型 std::unique_ptr 应该是 std::auto_ptr 的替代品。 它们的用法是否完全重叠(这样我可…

夏尔 2024-09-13 17:20:01 18 0

关于 auto_ptr::reset 的问题

请任何人解释一下来自 C++ 参考站点的这段代码: #include #include using namespace std; int main () { auto_ptr p; p.reset (new int); *p=5; cout…

回忆追雨的时光 2024-09-10 11:19:49 13 0
更多

推荐作者

佚名

文章 0 评论 0

今天

文章 0 评论 0

゛时过境迁

文章 0 评论 0

达拉崩吧

文章 0 评论 0

呆萌少年

文章 0 评论 0

孤者何惧

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文