草庐IT

unique_ids

全部标签

c++ - vector<unique_ptr> 的唯一拷贝

我有一个包含vector的类对象.我想要这个对象的拷贝来运行非常量函数。原始拷贝必须保持const。这样一个类的复制构造函数是什么样的?classFoo{public:Foo(constFoo&other):???{}std::vectorptrs;}; 最佳答案 您不能简单地复制std::vector因为std::unique_ptr不可复制,因此它将删除vector复制构造函数。如果您不更改存储在vector中的类型,那么您可以通过创建一个全新的vector来进行“复制”std::vector>from;//thishasthe

c++ - 为什么 unique_ptr 有一个 nullptr_t 构造函数?

我不清楚有什么好处。如果我有:Foo*foo=nullptr;std::unique_ptrunique_foo(foo);在那种情况下是否调用了nullptr_t构造函数?或者仅当您这样做时:std::unique_ptrunique_foo(nullptr);谢谢!有一些讨论here这是为了允许你传入nullptr_t,否则它不会编译,因为它不会转换为类型指针。所以我的问题可能是为什么它不转换? 最佳答案 一个可能的原因是采用unique_ptr::pointer参数的unique_ptr构造函数是显式。这意味着在没有uniqu

c++ - std::unique_ptr 是 RAII 的应用吗?

这是对它的准确描述吗?有道理吗?您是否保证在unique_ptr超出范围之前它指向的对象不会被删除[即使您没有使用unique_ptr]? 最佳答案 是的,std::unique_ptr遵循RAII设计原则。不,std::unique_ptr不会阻止其他代码做一些愚蠢的事情,比如在属于unique_ptr的指针上调用delete>。unique_ptr本身将在其拥有的对象上调用deleter1,当出现以下任一情况时:超出范围或unique_ptr被重新分配(通过operator=或reset)以指向不同的对象还可以通过移动到不同的智

ssh报错:no such identity: /xxx/xxx/.ssh/id_rsa: No such file or directory解决方案

ssh报错:nosuchidentity:/xxx/xxx/.ssh/id_rsa:Nosuchfileordirectory.Permissiondenied(publickey)解决方案最近在使用ssh方式连接公司跳板机时报错:Warning:Permanentlyadded'xxx'(ECDSA)tothelistofknownhosts.nosuchidentity:/xxx/xxx/.ssh/id_rsa:Nosuchfileordirectorynosuchidentity:/xxx/xxx/.ssh/id_dsa:Nosuchfileordirectorynosuchidenti

为什么形式需要JSF中的ID

在HTML中不可见形式。我想知道为什么表单具有与该功能匹配的ID。这是为了什么?看答案这id属性打开h:form组件不是强制性的。如果不使用它,JSF将为您提供/生成一个。

c++ - 为什么我会收到编译错误 "use of deleted function ' std::unique_ptr ...”

我收到一个巨大的编译错误信息c:\mingw\include\c++\6.1.0\bits\predefined_ops.h:123:18:error:useofdeletedfunction'std::unique_ptr::unique_ptr(conststd::unique_ptr&)[with_Tp=Deduction;_Dp=std::default_delete]'{returnbool(_M_comp(*__it1,*__it2));}当我将自定义比较器传递给STLset_difference函数时。我的代码:structValue{std::stringded_cod

c++ - 海湾合作委员会- "expected unqualified-id before ' )' token"

请耐心等待,我只是在学习C++。我正在尝试编写我的头文件(用于类),但我遇到了一个奇怪的错误。cards.h:21:error:expectedunqualified-idbefore')'tokencards.h:22:error:expected`)'before"str"cards.h:23:error:expected`)'before"r"“')'标记前的预期不合格ID”是什么意思?我做错了什么?编辑:抱歉,我没有发布完整的代码。/*Cardheaderfile[Author]*///NOTE:LanugageDocsherehttp://www.cplusplus.com/

postgresql设置id自增

创建序列:CREATESEQUENCEtable_name_id_seq;将序列与表的列关联:ALTERTABLEtable_nameALTERCOLUMNidSETDEFAULTnextval('table_name_id_seq');可选地,你可以设置序列的起始值、递增步长和最大值:--将序列的起始值设置为1ALTERSEQUENCEtable_name_id_seqSTARTWITH1;--将序列的递增步长设置为1ALTERSEQUENCEtable_name_id_seqINCREMENTBY1;--将序列的最大值设置为9999ALTERSEQUENCEtable_name_id_se

c++ - 将 std::unique_ptr 转换为 std::unique_ptr 到父类(super class)的正确方法是什么?

假设我有一个名为foo的类它继承自一个名为bar的类.我有一个std::unique_ptr到foo的实例我想将它传递给一个只接受std::unique_ptr的函数.我怎样才能转换指针以便它在我的函数中工作? 最佳答案 您可以转换std::unique_ptr右值std::unique_ptr:std::unique_ptrf(newfoo);std::unique_ptrb(std::move(f));显然,指针将由b拥有如果b被摧毁bar需要有一个virtual析构函数。 关于c+

c++ - std::unique_ptr<T[]>::reset 在 gcc 6 中的实现

从C++中的GCC6开始,unique_ptr::reset的声明/定义方法(不是那个,只接受nullptr_t)看起来像这样:template,__and_,is_pointer,is_convertible::type(*)[],element_type(*)[]>>>>>voidreset(_Up__p)noexcept{usingstd::swap;swap(std::get(_M_t),__p);if(__p!=nullptr)get_deleter()(__p);}这在某些时候已更改以实现N4089.根据该文件:Thisfunctionbehavesthesameasthe