草庐IT

unique_name

全部标签

使用 unique_ptr 包含 char 数组的 C++ 对象

我正在寻找一种方法来使用unique_ptr来分配一个结构,该结构包含一个char数组,其中包含动态设置的字节数以支持不同类型的消息。假设:structMyMessage{uint32_tid;uint32_tdata_size;chardata[4];};如何将下面的send_message()转换为使用智能指针?voidsend_message(void*data,constsize_tdata_size){constautomessage_size=sizeof(MyMessage)-4+data_size;constautomsg=reinterpret_cast(newcha

c++ - unique_ptr 作为模板参数

为什么要在VS2017中编译?#include#includeusingnamespacestd;structx{x(){coutvoidfoo(T&&item){structboo{Titem;boo(T&&t):item(std::move(t)){}};newboo(std::move(item));}intmain(){std::unique_ptrb(newx);foo(b);//IwouldexpectthatIshouldputstd::move(b)here.}按照编写的代码,输出是x()~x()如果foo(b)行写为foo(std::move(b)),那么输出就是x(

c++ - 处理数组时 make_unique 和 make_shared 之间的区别

从C++17开始,您可以使用make_unique为了创建指向数组的智能指针,例如:unique_ptrptr=make_unique(10);这将创建一个指向10个元素数组的智能指针(将调用适当的deleter[]的事实也很棒)。但是根据thismake_shared不支持此类功能(至少在C++17中不支持,据我所知):shared_ptrptr=make_shared(10);上面的代码显然是非法的。事实上,我的VisualStudio2017(v141)吐出以下错误:C2070:'int[]':illegalsizeofoperand'有趣的是shared_ptr本身确实支持数组

c++ - 为什么 unique_ptr 不阻止自定义删除器的切片?

std::unique_ptr与自定义删除器的行为基于删除器的静态类型.没有多态性,没有基于运行时传递的实际删除器的运行时行为,因为提供的派生删除器被切片为声明的删除器的静态类型。(Itisdesignedthiswayinpurpose,toallowthesizeofunique_ptrwithdefaultdeleterorwithcustomdeleterwithoutanydatamembers,tohavesamesizeasarawpointer).带有自定义删除器的unique_ptr的静态行为:classA{};structBaseDeleter{virtualvoi

c++ - 是否有用于 boost::interprocess 的 'upgrade_to_unique_lock'?

我正在寻找在偏向编写器读取器/编写器模型中的两个(或多个)进程之间有效共享数据block的最佳方法。我当前的测试是使用boost::interprocess。我已经创建了一些managed_shared_memory并试图通过使用存储在共享内存中的进程间互斥来锁定对数据block的访问。但是,即使在读取器上使用sharable_lock并在写入器上使用upgradable_lock时,客户端在写入操作期间将读取碎片值而不是阻塞。在单个进程中的线程之间进行类似的读写器设置时,我使用upgrade_to_unique_lock来解决这个问题。但是,我还没有找到它的boost::interp

Name for argument of type [java.lang.String] not ... Ensure that the compiler uses the ‘-parameters’

更多信息:https://oldmoon.top/post/191简介使用最新版的Springboot3.2.1搭建开发环境进行开发,调用接口时出现奇怪的错。报错主要信息如下:Nameforargumentoftype[java.lang.String]notspecified,andparameternameinformationnotavailableviareflection.Ensurethatthecompilerusesthe‘-parameters’flag.官方说明中一直强调@PathVariable的使用,并没有提及@RequestParam,阅读官方文档@RequestPa

c++ - 将 unique_ptr 插入 map ,指针被销毁

我有以下(简化的)类(class):classOperator{private:std::map>op;public:templatevoidinsertOperand(std::stringconst&s,To=T()){op.insert(std::pair>(s,std::move(std::unique_ptr(newT(o))));}voidsetOperandsValue(std::stringconst&o,intv){op.find(o)->second->setValue(v);}};插入一个新的Operand没有任何问题。然而,当函数返回时,析构函数被调用,因此ma

c++ - Visual Studio Name Mangling "YAPEAV"和 Mysql 连接器

将我的代码与MySQLConnectorC++1.1.0链接时出现Unresolvedexternalsymbol错误。这是错误消息:6>database.lib(db_manager.obj):errorLNK2019:unresolvedexternalsymbol"classsql::mysql::MySQL_Driver*__cdeclsql::mysql::get_driver_instance(void)"(?get_driver_instance@mysql@sql@@YAPAVMySQL_Driver@12@XZ)referencedinfunction"classsq

c++ - 窗体头文件中的 "error C2653: System is not a class or a namespace name",Visual C++

我之前关于同一项目的问题:one和two.没有必要阅读它们;只知道我正在尝试在VisualC++项目中使用nativeC++SDK。这比我最初想象的要棘手得多,但是这个网站关于ExtendinganativeC++projectwithmanagedcode已经帮助了我很多。按照最后一个链接的说明,我已将一个表单添加到我的nativeC++项目中,该项目已自动将项目转换为CLR项目。只有MainForm.cpp和Interface.cpp(允许nativeC++代码创建和显示MainForm的文件)使用/clr编译旗虽然;其他文件保持原样。我现在遇到的问题是,VisualStudio似

c++ - QMap 和 std::unique_ptr

我试图防止裸指针,防止内存泄漏等。我还想将int映射到INuiSensor*.由于我也在使用Qt,所以我尝试使用QMap>来执行此操作,但QMap的源代码使这变得不可能:templateQ_INLINE_TEMPLATEtypenameQMap::iteratorQMap::insert(constKey&akey,constT&avalue){detach();Node*n=d->root();Node*y=d->end();Node*last=0;boolleft=true;while(n){y=n;if(!qMapLessThanKey(n->key,akey)){last=n;