草庐IT

mod_unique_id

全部标签

c++ - make_unique 不编译

我正在尝试为std::unique_ptr创建和使用make_unique,就像std::make_shared存在于std::shared_ptrdescribedhere.赫伯萨特mentionsmake_unique的可能实现如下所示:templatestd::unique_ptrmake_unique(Args&&...args){returnstd::unique_ptr(newT(std::forward(args)...));}它似乎对我不起作用。我正在使用以下示例程序://testproject.cpp:Definestheentrypointfortheconsole

c++ - 使用带有 unique_ptr 的自定义删除器

借助shared_ptr,您可以使用自定义删除器,例如:autofp=shared_ptr(fopen("file.txt","rt"),&fclose);fprintf(fp.get(),"hello\n");这将记住fclose文件,无论函数如何退出。但是,引用局部变量似乎有点矫枉过正,所以我想使用unique_ptr:autofp=unique_ptr(fopen("file.txt","rt"),&fclose);但是,这不会编译。这是缺陷吗?有简单的解决方法吗?我是否遗漏了一些微不足道的东西? 最佳答案 应该是unique

C++ - vector<> 中的 std::unique_ptr 是 nullptr

我想将Particle对象存储在vector对象中,以便稍后访问它。这些粒子(Electrons和Protons)继承自包含toString()虚方法的Particle类。此toString()方法随后在Electron和Proton类中被覆盖。当我读取vector容器时,我想访问Electron或Proton特定的toString()方法,而不是粒子。显然,一种方法是使用std::unique_ptr。这是我尝试运行的代码的一部分:intmain(){/**/std::vector>particles(nbParticles);particles.push_back(std::uni

c++ - 在没有 std::move 的情况下如何按值返回 unique_ptr?

这个问题在这里已经有了答案:Returningunique_ptrfromfunctions(7个答案)关闭8年前。std::unique_ptrptr(){std::unique_ptrp(newint(3));returnp;//Whydoesn'tthisrequireexplicitmoveusingstd::move?}//Whydidn'tthedatapointedtoby'p'isnotdestroyedherethoughpisnotmoved?intmain(){std::unique_ptra=ptr();//Whydoesn'tthisrequirestd::m

c++ - boost 序列化 std::unique_ptr 支持

boost序列化库支持std::unique_ptr的序列化吗?我试图编译下面的代码,但如果我包含boost::archive::text_oarchiveoa(ofs);oa行,编译器(顺便说一句,带有-std=c++11标志的gcc4.7)抛出一个错误/usr/include/boost/serialization/access.hpp:118:9:错误:‘classstd::unique_ptr’没有名为‘serialize’的成员#include#include#include#include#includeclassMyDegrees{public:voidsetDeg(in

c++ - '[' token 之前的预期不合格 ID

我知道这个错误一般是语法错误,但我似乎找不到这段代码有什么问题。谁能帮我指出来?以下是我遇到的错误:deli.cc:10:7:error:expectedunqualified-idbefore‘[’tokenint[]myCashierNums;^deli.cc:11:7:error:expectedunqualified-idbefore‘[’tokenint[]myOrderNums;^这是我在Ubuntu14.0464位上使用g++编译的程序。#include#includeusingnamespacestd;classSandwichBoard{//private:intmy

c++ - 通过进程ID获取hwnd C++

如果我知道进程ID,我如何获取应用程序的HWND?任何人都可以张贴sample吗?我正在使用MSVC++2010。我找到了Process::MainWindowHandle,但我不知道如何使用它。 最佳答案 HWNDg_HWND=NULL;BOOLCALLBACKEnumWindowsProcMy(HWNDhwnd,LPARAMlParam){DWORDlpdwProcessId;GetWindowThreadProcessId(hwnd,&lpdwProcessId);if(lpdwProcessId==lParam){g_HWN

c++ - 尽管使用 unique_ptr 内存泄漏

我有一个类的构造函数,它用传递给它的值初始化该类内部的unique_ptr。出于某种原因,valgrind提示内存泄漏:22,080(24direct,22,056indirect)bytesin1blocksaredefinitelylostinlossrecord6of6at0x4C2C7A7:operatornew(unsignedlong)(in/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)by0x4A64FB:VectorBasedNodeOrder::VectorBasedNodeOrder(VectorBasedN

kafka生产者发送消息报错 Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected

报这个错误是因为kafka里的配置要修改下在config目录下server.properties配置文件这下发送消息就不会一直等待,就可以发送成功了

c++ - 如何在 C++ 中将 std::thread::id 转换为字符串?

如何在C++中将std::thread::id类型转换为字符串?我正在尝试将std::this_thread::get_id()生成的输出类型转换为字符串或字符数组。 最佳答案 automyid=this_thread::get_id();stringstreamss;ss 关于c++-如何在C++中将std::thread::id转换为字符串?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/que