gpt4 book ai didi

c++ - 如何创建 std::string 包装器,将 ptr 保留到 std::string 并将 ptr 保留到创建该包装器实例的类中的特殊类函数?

转载 作者:行者123 更新时间:2023-11-28 08:11:15 28 4
gpt4 key购买 nike

我有课。它有一个函数 void delete_ptr(void *);void push_into(std::set<my_string> ** pps); .我有这个类的 10 个实例。每个都分配在不同的堆上。我的程序在主堆中,与我的 map 所在的位置相同。我想调用我的每个类实例 push_into用我的主要 map 。每个 push_into 都会调用 (**pps).insert(std::string("Hello str"));(**pps).insert("Hello char"); .如何创建这样的 my_string将保留 **std::string 的类(class)在里面还有ptrdelete_ptr创建 my_string 的类类实例?

我想知道的主要目标是:

  • 如何创建其构造函数以使其保留指向创建它的实例的字符串和 delete_ptr 的指针?

最佳答案

您可以将 boost::shared_ptrcustom deallocator 一起使用.使用 boost::bind

提供您的 delete_ptr 作为自定义释放器

关于c++ - 如何创建 std::string 包装器,将 ptr 保留到 std::string 并将 ptr 保留到创建该包装器实例的类中的特殊类函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9005806/

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