草庐IT

function-call

全部标签

c++ - 为什么 std::function 在这种情况下不起作用?

假设我有一个类型:structmy_type{doubleoperator()(inta){return3.1415;}};然后我想将它包装在std::function中。考虑两种不同的方法:my_typem_t;std::functionf(std::move(m_t));std::cout一切如我所料,打印出了PI的第一位数字。然后第二种方法:std::functionff(my_type());std::cout在我看来,这段代码与第一个代码绝对相同。rvalue作为参数传递给function包装器。但问题是,第二个代码无法编译!我真的不知道为什么会这样。

c++ - 模棱两可的成员模板查找

对此question的回答在下面的代码中说:#includeusingstd::vector;structfoo{templatevoidvector();};intmain(){foof;f.vector();//ambiguous!}main中的最后一行是不明确的,因为编译器不仅在foo中查找vector,而且还作为从main。所以它找到了std::vector和foo::vector。要解决此问题,您必须编写f.foo::vector();我已经在所有流行的C++编译器(g++、clang++、vc++和IntelC++)上试过这个程序,所有编译器都编译这个程序没有任何错误。那么

c++ - std::tr1::function 和 std::tr1::bind

我在C++类中使用非常复杂的C函数时遇到问题(重写C函数不是一个选项)。C函数:typedefvoid(*integrand)(unsignedndim,constdouble*x,void*fdata,unsignedfdim,double*fval);//Thisone:intadapt_integrate(unsignedfdim,integrandf,void*fdata,unsigneddim,constdouble*xmin,constdouble*xmax,unsignedmaxEval,doublereqAbsError,doublereqRelError,double

c++ - 从结构中调用 Pointer-to-Member-Function 指向的函数

我有一个具有特殊数据结构的类Test。Test类的成员是std::map,其中键是std::string,映射值是struct定义如下:typedefstruct{void(Test::*f)(void)const;}pmf_t;map初始化正常。问题是当我试图调用指向的函数时。我编了一个重现问题的玩具示例。在这里:#include#includeusingnamespacestd;classTest;typedefvoid(Test::*F)(void)const;typedefstruct{Ff;}pmf_t;classTest{public:Test(){pmf_tpmf={&T

c++ - 如何在不显式定义函数的情况下创建函数的 std::vector?

我想创建一个std::vector对象(或任何其他标准或自定义容器类型),其中包含签名完全相同的自定义和任意函数的元素。应该是这样的://Definethefunctionsandpushthemintoavectorstd::vectorMyFunctions;MyFunctions.push_back(double(intn,floatf){return(double)f/(double)n;});MyFunctions.push_back(double(intn,floatf){return(double)sqrt((double)f)/(double)n;});//...MyF

c++ - clang++ (3.3/Xcode) 中 std::function 的定义在哪里

问题已解决=>看到最后的更新我正在尝试使用std::function但看起来只包括不提供定义。我试图编译以下代码:#includestd::functionf=nullptr;以c++11作为编译选项:%clang++-c-std=c++11t.cc原因:t.cc:3:6:error:notypenamed'function'innamespace'std'std::functionf=nullptr;~~~~~^t.cc:3:14:error:expectedunqualified-idstd::functionf=nullptr;^2errorsgenerated.我错过了什么?我

c++ - C++ 模板是否能够从父类获取 "forward any class function"?

classFoo{public:voidmethodA();};classManagedFoo{FoofooInst;public:voidmethodA(){doSomething();fooInst.methodA();}};现在我想把ManagedFoo做成一个模板,管理任何类而不仅仅是Foo,并且在调用Foo的任何函数之前,先调用doSomething。templateclassManager{_TyManaged_managedInst;voiddoSomething();public:/*Forwardeveryfunctioncalledby_managedInst*//

c++ - 错误 C2731 : 'wWinMain' : function cannot be overloaded

我将一个旧项目从VC6升级到VS2008,现在我得到这个编译错误:errorC2731:'wWinMain':functioncannotbeoverloaded在这些代码行:intAPIENTRY_tWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow)同一项目在VC6下编译良好。 最佳答案 谢谢大家,我终于找到了真正的罪魁祸首,这是一个错字,我使用LPSTRlpCmdLine而不是LPTSTRlpCmdLine。真正的谜团是为什么

c++ - std::function 与函数指针

这个问题在这里已经有了答案:ShouldIusestd::functionorafunctionpointerinC++?(6个答案)关闭7年前。有什么区别吗?“保存/传输”功能的最佳方式是什么?functionfcn=[](intpar){std::cout

c++ - __has_cpp_attribute 不是 'function-like' 宏?

我正在尝试将[[deprecated]]属性引入我的代码库。然而,并不是所有我需要支持的编译器都支持这种语法(在attributestandardizationproposalN2761中描述了标准化之前不同编译器使用的各种方法)。因此,我尝试在此属性中有条件地编译,首先使用__has_cpp_attribute类宏函数(如果可用),如下所示:#ifdefined(__has_cpp_attribute)&&__has_cpp_attribute(deprecated)#defineDEPRECATED(msg)[[deprecated(msg)]]#elifOTHER_COMPILE