草庐IT

non-unique

全部标签

c++ - unique_ptr VS auto_ptr

这个问题在这里已经有了答案:关闭9年前。PossibleDuplicate:std::auto_ptrtostd::unique_ptrWhatC++SmartPointerImplementationsareavailable?假设我有这个struct:structbar{};当我像这样使用auto_ptr时:voidfoo(){auto_ptrmyFirstBar=newbar;if(){auto_ptrmySecondBar=myFirstBar;}}然后在auto_ptrmySecondBar=myFirstBar;C++将所有权从myFirstBar转移到mySecondBa

c++ - 为什么 const/non-const 函数重载的继承不明确?

我试图创建两个类,第一个类是函数的非const实现,第二个类是const实现。这是一个小例子:classBase{protected:intsome;};classA:publicvirtualBase{constint&get()const{returnsome;}};classB:publicvirtualBase{int&get(){returnsome;}};classC:publicA,B{};Ctest;test.get();//ambiguous对get函数的调用不明确。不管const版本需要匹配更多的需求。(在constC上调用get也是模棱两可的,但有一个可能的函数可

c++ - 为什么 const/non-const 函数重载的继承不明确?

我试图创建两个类,第一个类是函数的非const实现,第二个类是const实现。这是一个小例子:classBase{protected:intsome;};classA:publicvirtualBase{constint&get()const{returnsome;}};classB:publicvirtualBase{int&get(){returnsome;}};classC:publicA,B{};Ctest;test.get();//ambiguous对get函数的调用不明确。不管const版本需要匹配更多的需求。(在constC上调用get也是模棱两可的,但有一个可能的函数可

c++ - unique_ptr 编译错误

如果我告诉你我无法编译它,我想这会很尴尬。你能帮帮我吗:#includeusingnamespacestd;intmain(){std::unique_ptrp1(newint(5));return0;}$gccmain.cppmain.cpp:Infunction‘intmain()’:main.cpp:6:2:error:‘unique_ptr’wasnotdeclaredinthisscopemain.cpp:6:13:error:expectedprimary-expressionbefore‘int’main.cpp:6:13:error:expected‘;’before‘

c++ - unique_ptr 编译错误

如果我告诉你我无法编译它,我想这会很尴尬。你能帮帮我吗:#includeusingnamespacestd;intmain(){std::unique_ptrp1(newint(5));return0;}$gccmain.cppmain.cpp:Infunction‘intmain()’:main.cpp:6:2:error:‘unique_ptr’wasnotdeclaredinthisscopemain.cpp:6:13:error:expectedprimary-expressionbefore‘int’main.cpp:6:13:error:expected‘;’before‘

C++ Qt std::unique_ptr Qt 版本在哪里?

所以在Qt中编程时,我喜欢尽可能使用Qt实现。据我所知,没有Qt版本的std::unique_ptr还是有?如果Qt不存在,那么在Qt中产生“相同”结果的替代方案是什么? 最佳答案 Qt等价于std::unique_ptr是QScopedPointer.由于不支持移动语义,它的用处明显减少,使其更接近C++03std::auto_ptr的实用性(Whyisauto_ptrbeingdeprecated?)。 关于C++Qtstd::unique_ptrQt版本在哪里?,我们在StackO

C++ Qt std::unique_ptr Qt 版本在哪里?

所以在Qt中编程时,我喜欢尽可能使用Qt实现。据我所知,没有Qt版本的std::unique_ptr还是有?如果Qt不存在,那么在Qt中产生“相同”结果的替代方案是什么? 最佳答案 Qt等价于std::unique_ptr是QScopedPointer.由于不支持移动语义,它的用处明显减少,使其更接近C++03std::auto_ptr的实用性(Whyisauto_ptrbeingdeprecated?)。 关于C++Qtstd::unique_ptrQt版本在哪里?,我们在StackO

c++ - unique_ptr 可以采用 nullptr 值吗?

此代码片段有效吗?:unique_ptrp(newA());p=nullptr;也就是说,我可以将nullptr分配给unique_ptr吗?还是会失败?我用g++编译器尝试了这个,它成功了,但是其他编译器呢? 最佳答案 它会起作用。来自C++11标准的第20.7.1.2.3/8-9段关于unique_ptr类模板:unique_ptr&operator=(nullptr_t)noexcept;Effects:reset().Postcondition:get()==nullptr这表示类模板的定义unique_ptr包含opera

c++ - unique_ptr 可以采用 nullptr 值吗?

此代码片段有效吗?:unique_ptrp(newA());p=nullptr;也就是说,我可以将nullptr分配给unique_ptr吗?还是会失败?我用g++编译器尝试了这个,它成功了,但是其他编译器呢? 最佳答案 它会起作用。来自C++11标准的第20.7.1.2.3/8-9段关于unique_ptr类模板:unique_ptr&operator=(nullptr_t)noexcept;Effects:reset().Postcondition:get()==nullptr这表示类模板的定义unique_ptr包含opera

c++ - unique_ptr 与 shared_ptr 中的删除器类型

这个问题在这里已经有了答案:Whydoesunique_ptrtaketwotemplateparameterswhenshared_ptronlytakesone?(2个回答)关闭7年前。当我发现标准以两种完全不同的方式定义了std::unique_ptr和std::shared_ptr时,我觉得这非常奇怪可能拥有。这是来自cppreference::unique_ptr的声明和cppreference::shared_ptr:template>classunique_ptr;templateclassshared_ptr;如您所见,unique_ptr将Deleter对象的类型“保