草庐IT

unique_name

全部标签

c++ - 什么时候 'identifier' 在 C++ 中是 'name'?

C++中的“标识符”何时称为“名称”?我主要读到术语“名称”被过度使用,而不是示例中的“标识符”:structS{inti};Sthing1;在这种情况下,thing1是名称还是标识符?还是术语“标识符”和“名称”是类似的?在C中,在引用对象时是否使用术语“名称”? 最佳答案 在C++中,标识符只是一个数字、字母和_的序列。,不以数字开头。这样的标识符可以出现在任何地方,并且不必标识任何东西,尽管它的名字(没有双关语意)。术语名称将含义与特定语法结构相关联。C++规范规定,如果以下语法结构之一表示实体(对象、类、模板和依此类推)或标

c++ - boost::asio 与 boost::unique_future

根据http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/overview/cpp2011/futures.html,我们可以将boost::asio与std::future一起使用。但是我找不到任何关于使用boost::unique_future的信息,它有更多的功能,比如then()。我该如何使用? 最佳答案 Boost.Asio仅提供一流的异步操作支持,以返回C++11std::future或stackfulcoroutines中的实际值.尽管如此,requireme

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

springboot启动报错Error creating bean with name requestMappingHandlerMapping defined in class path resou

报错信息:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'requestMappingHandlerMapping'definedinclasspathresource[com/huashang/config/WebMvcConfig.class]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IllegalStateException:Ambiguousmapping.Cannotmap'projectContr

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++ - 尽管使用 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++ - 错误消息 : name lookup of ‘jj’ changed for ISO ‘for’ scoping,(如果您使用 ‘-fpermissive’,G++ 将接受您的代码)

错误是:Infunction‘intreturnShortestWeightedBranch(std::vector>*)’:error:namelookupof‘jj’changedforISO‘for’scopingnote:(ifyouuse‘-fpermissive’G++willacceptyourcode)代码是:for(inti=0;i这里可能是什么问题?编辑1:我更改了以下内容:for(intjj=0;jj到:intjj;for(jj=0;jj现在它正在工作!!我不明白原因。 最佳答案 内部for语句的末尾有一个分号