草庐IT

SOME_UNIQUE_VALE

全部标签

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++ - 尽管使用 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

c++ - 在 map 中使用 unique_ptr 时删除 std::pair 中的函数

我有一段C++代码,我不确定它是否正确。考虑以下代码。#include#include#includeusingnamespacestd;intmain(intargc,char*argv[]){vector>>v;v.resize(5);returnEXIT_SUCCESS;}GCC编译这段代码没有问题。然而,英特尔编译器(版本19)因错误而停止:/usr/local/[...]/include/c++/7.3.0/ext/new_allocator.h(136):error:function"std::pair::pair(conststd::pair&)[with_T1=cons

c++ - `unique_ptr` 上的原子操作

std::shared_ptrhasspecializationsforatomicoperations像atomic_compare_exchange_weak和family,但我找不到关于std::unique_ptr的等效特化的文档。有没有?如果不是,为什么不呢? 最佳答案 可以提供std::shared_ptr的原子实例的原因并且不可能为std::unique_ptr这样做在他们的签名中暗示。比较:std::shared_ptr对比std::unique_ptr其中D是删除器的类型。std::shared_ptr需要分配一个

c++ - std::move 和 unique_ptr::reset 之间有什么区别?

对于std::unique_ptr的p1和p2,std::move()有什么区别>和std::unique_ptr::reset()?p1=std::move(p2);p1.reset(p2.release()); 最佳答案 根据[unique.ptr.single.assign]/2中移动分配的标准规范,答案应该是显而易见的:Effects:Transfersownershipfromuto*thisasifbycallingreset(u.release())followedbyanassignmentfromstd::forw

c++ - extern const char* const SOME_CONSTANT 给我链接器错误

我想像这样在API中提供一个字符串常量:externconstchar*constSOME_CONSTANT;但是如果我在我的静态库源文件中将它定义为constchar*constSOME_CONSTANT="test";当链接到该库并使用SOME_CONSTANT时,我遇到链接器错误:Error1errorLNK2001:unresolvedexternalsymbol"charconst*constSOME_CONSTANT"(?SOME_CONSTANT@@3QBDB)从externconstchar*const声明和定义中删除指针常量(第二个const关键字)使其工作。如何使用

c++ - std::bind 通常与仅移动类型一起使用,特别是 std::unique_ptr 吗?

我正在尝试使用boost::asio并遇到了一些问题。我正在尝试编译以下代码:std::unique_ptrbuffer=buffers.pop();std::functiont=std::bind(&tcp_client::handle_read_done,this,std::placeholders::_1,std::placeholders::_2,std::move(buffer));如果我排除std::move(buffer),一切正常,当然是从handle_read_done的签名和作为std::bind中传递的参数。当试图将它传递给boost::asio::async_r

c++ - 为什么不再允许从数组的 unique_ptr 创建 shared_ptr?

来自cppreference:InC++11andC++14itisvalidtoconstructastd::shared_ptrfromastd::unique_ptr:std::unique_ptrarr(newint[1]);std::shared_ptrptr(std::move(arr));Sincetheshared_ptrobtainsitsdeleter(astd::default_deleteobject)fromtheunique_ptr,thearraywillbecorrectlydeallocated.ThisisnolongerallowedinC++17

SOME/IP TTL 在各种Entry 中各是什么意思?有什么限制?

1服务发现SOME/IPSD服务发现主要用于定位服务实例检测服务实例状态是否在运行发布/订阅行为管理SOME/IPSD也是SOME/IP消息,遵循SOME/IP消息格式,有固定的MessageID、RequestID以及MessageType等。并对SOME/IPPayload进行了详细的定义。 SOME/IPSD只用UDP协议的30490端口通信。2SOME/IPSD的Payload中主要包含Entry和Option:2.1Entry:Entry用于提供服务、发现服务、订阅事件组。SOME/IPTTL是指SOME/IP服务发现(SD)中的Entry的生存时间(TimeToLive),它表示一

c++ - 在这种情况下我应该使用 unique_ptr 还是 shared_ptr?

在我的QT应用程序的主窗口中,我使用std::shared_ptr来保存指向我的网络服务实例的指针,该实例管理与多个客户端的所有连接。现在,我必须将这个指针传递给多个子窗口,以便它们可以与客户端通信。我最好在主窗口和子窗口中使用std::shared_ptr成员变量并在创建子窗口时传递复制它,还是使用std更好::unique_ptr并将原始指针传递给子窗口,因为主窗口无论如何都会比子窗口长寿?非常感谢! 最佳答案 主要的实际区别是当主窗口被销毁而子窗口仍然存在并正在使用网络服务时会发生什么:如果您使用unique_ptr并传递原始