草庐IT

name-binding

全部标签

c++ - std::function 和 std::bind 做动态内存分配吗?

如果我这样做:-classThing{...voidfunction(conststd::string&message);};std::list>work;在“Thing”的一些成员中work.push_back(std::bind(&Thing::function,this,"Hello"));调用std::bind或使用std::function是否会导致使用new或其他方式进行任何动态内存分配?或者所有的存储空间都是在编译时分配的?如果标准没有说明任何内容,那么在visualstudio2012中呢,因为我的程序只需要在那里构建,为了提高效率,我可能需要在我考虑使用这种机制的地方

c++ - 为什么可以间接地将右值绑定(bind)到左值引用而不是直接绑定(bind)?

根据我的阅读和了解,您不能将右值表达式绑定(bind)到左值引用。然而,我所看到的是,您可以将右值绑定(bind)到右值引用,并且由于命名的右值引用本质上是左值,因此您可以将它绑定(bind)到左值引用。不允许将右值绑定(bind)到左值引用背后的原因是什么。是否出于优化目的?举个例子:#includeusingstd::cout;voidbar(int&b){cout 最佳答案 这是C++的基本规则,它可以防止错误:intfoo();int&x=3;//whoopsint&y=foo();//whoops(sometimes)“右

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++ - 一个 VS2010 错误?允许在没有警告的情况下绑定(bind)对右值的非常量引用?

stringfoo(){return"hello";}intmain(){//belowshouldbeillegalforbindinganon-const(lvalue)referencetoarvaluestring&tem=foo();//belowshouldbethecorrectoneasonlyconstreferencecanbebindtorvalue(mostimportantconst)conststring&constTem=foo();}GCC是给出编译错误的好工具:std::string&类型的非常量引用从std类型的临时值初始化无效::字符串VS2008

C++/Xcode 套接字绑定(bind)()错误

当尝试处理来自sys/sockets.hbind()的返回值(应该是int)时,Xcode编译失败并出现错误二进制表达式的无效操作数(“__bind”和“int”)它似乎为bind()提取了不正确的函数定义,因为当我从上下文菜单中选择“跳转到定义”时,它给了我三个选项:2个来自functional.cpp的定义,1个来自sys/sockets。H。我的代码中包含sys/sockets,如何强制编译器使用正确的定义? 最佳答案 使用::bind或去掉usingnamespacestd;。

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语句的末尾有一个分号

c++ - 编译器差异 : Interaction between alias resolution and name lookup

考虑这段代码:usingtype=long;namespacen{usingtype=long;}usingnamespacen;intmain(){typet;}这可以在Clang3.7和GCC5.3上干净地编译,但是MSVC19*给出以下错误消息:main.cpp(9):errorC2872:'type':ambiguoussymbolmain.cpp(1):note:couldbe'longtype'main.cpp(4):note:or'n::type'这段代码格式是否正确?标准的哪一部分说明在歧义检查之前是否已解析别名?请注意,如果您更改其中一个别名,Clang和GCC都会给

c++ - 将左值绑定(bind)到右值引用——g++ 错误?

作为对anotherquestion的回答我想贴出下面的代码(也就是我想贴出基于这个思路的代码):#include#include//std::is_same,std::enable_ifusingnamespacestd;templatestructBoxed{Typevalue;templateBoxed(Argconst&v,typenameenable_if::value,Arg>::type*=0):value(v){wcoutv){}intmain(){inti=5;function(i);//但是,虽然MSVC11.0在最后一次调用时阻塞,但IHMO应该如此,而MinGW

c++ - 为什么第一个函数调用绑定(bind)到第一个函数?

这个问题在这里已经有了答案:Whydoespointerdecaytakepriorityoveradeducedtemplate?(1个回答)关闭6年前。为什么第一个函数调用(cm(car);)绑定(bind)到第一个函数?我知道第二次调用绑定(bind)到第二个函数,因为它不是模板,尽管两者都是完美匹配。如果第一个函数定义为固定数组长度的非模板,如:voidcm(constchar(&h)[8]){cout然后它再次被选中而不是第二个(第二个调用将以这种方式模棱两可)。代码:templatevoidcm(constchar(&h)[N]){std::cout输出:const(&)[

c++ - 本地结构中是否允许成员声明 `decltype(name) name;`,其中第一个名称指的是封闭范围?

例子:intmain(){inta=0;structX{decltype(a)a;};return0;}decltype(a)引用了main中的局部a,而它声明的成员同名。Clang编译没有任何问题,MSVC14也是如此。G++提示它,添加-fpermissive让它通过prog.cc:6:21:error:declarationof'intmain()::X::a'[-fpermissive]decltype(a)a;^prog.cc:3:9:error:changesmeaningof'a'from'inta'[-fpermissive]inta=0;哪种行为符合标准?