草庐IT

MYLIB_FUNCTION_ATTRIBUTE

全部标签

c++ - 使用 boost::bind 和 boost::function 作为回调的类成员函数

我正在努力设置一个成员函数作为我正在使用的C库的回调。C库像这样设置回调:typedefint(*functionPointer_t)(myType1_t*,myType2_t*,myType3_t*);setCallback(param1,param2,functionPointer,param4)我想使用boost::bind(如果可能的话)来传递函数指针。我更希望被指向的函数是实例化类的成员,而不是静态成员。例如ClassA{public:A();protected:intmyCallback(myType1_t*,myType2_t*,myType3_t*);//akafunc

c++ - 为什么 g++ 从带有转换运算符和不可访问的函数调用运算符的类型中初始化 std::function<> 失败?

此代码在g++4.9及更高版本(包括从svncurrent构建)中失败,但在没有警告的情况下使用clang++和Microsoft编译器(来自VS2015。)编译#includestructA{voidoperator()()const{}};structB{voidoperator()()const{}};structC:privateA,privateB{operatorstd::function()const{returnnullptr;}};intmain(){std::functionf{C{}};}main()中f的构造失败,因为operator()在structC中不明确

c++ - 可以使用默认参数复制包含 lambda 的 std::function 吗?

有没有什么方法可以从lambda恢复类型信息,默认参数存储在std::function中,但其类型中没有这些参数?std::functionf1=[](inti=0){};std::functionf2=[](inti=0){};std::functionf3=f1;//errorstd::functionf4=f2;//error看看std::function的复制构造函数,其他函数类型没有部分模板特化,所以我想这个信息丢失了,这只是你不能将一种类型的函数分配给的情况另一种类型的函数,即使在内部它们都可以调用该函数。这个对吗?是否有任何解决方法来实现这一目标?我正在查看std::fu

c++ - 使用 std::function 的隐式转换

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicates:Whycan'tmyC++compilerdeducetemplateargumentforboostfunction?Isn'tthetemplateargument(thesignature)ofstd::functionpartofitstype?我有以下内容:#includevoidFoo(std::function);voidFoo(std::function);voidBar();intmain(){Foo(Bar);//Error:ambiguousFoo([](){});//Error:am

c++ - 错误 C4996 : 'std::_Copy_impl' : Function call with parameters that may be unsafe

我知道这个问题在SO中被问过很多次,但这是与其他问题的不同。CompilerError:FunctioncallwithparametersthatmaybeunsafeVisualStudioWarningC4996xutility(2227):warningC4996:'std::_Copy_impl'失败的代码片段DWORDdwNumberOfNames=pExportDirectory->NumberOfNames;LPDWORDdwNames=(LPDWORD)((LPBYTE)hDLL+pExportDirectory->AddressOfNames);std::vecto

c++ - 类型特征 : Check if class have specific function (maybe inherit)

我知道有很多方法可以检测一个类是否具有特定功能,但没有一种方法真正适合我的具体情况。我当前用于检查正确成员函数的实现工作正常,继承函数除外。#includetemplateclassHasFoo{templatestructCheck;templatestaticstd::true_typeTest(Check*);templatestaticstd::false_typeTest(...);public:staticconstexprboolvalue=decltype(Test(0))::value;};structA{intfoo(float);};structB:publicA

C++ 私有(private)函数 : Whether to pass class member variable by function parameter, 或不

这是一个在C++类实现中反复出现的问题。我很好奇人们在这里的想法是什么。您更喜欢哪种代码,为什么?classA{public:/*Constructors,Destructors,Publicinterfacefunctions,etc.*/voidpublicCall(void);private:voidf(void);CMyClassm_Member1;};与voidA::publicCall(void){f();}voidA::f(void){//dosomestuffpopulatingm_Member1}或者替代方案:classA{public:/*Constructors,

c++ - 为什么 std::function 在签名中接受 this 引用?

成员函数有一个隐含的this指针参数。为什么std::function接受这个签名,那么,这里的S是一个简单的类?(completesample)std::functionfunc=&S::foo;调用它也可以,并且可以区分对象:Ss1={5};Ss2={6};func(s1);//prints5func(s2);//prints6我通常期望的是它需要一个指针,它也能正常工作:(completesample)std::functionfunc=&S::foo;Ss1={5};Ss2={6};func(&s1);//prints5func(&s2);//prints6当隐式this参数是

c++ - 虚拟方法 VS std::function 成员变量在性能方面

游戏引擎有这个类:classMouseListener{public:MouseListener();virtualvoidOnMouseDown(intmx,intmy);virtualvoidOnMouseUp(intmx,intmy);...};每个想要监听鼠标输入的对象,都必须固有该类并覆盖它的方法。为了不必每次都声明一个新类型,该类被修改为:classMouseListener{public:MouseListener();std::functionOnMouseDown;std::functionOnMouseUp;...};现在可以这样使用这个类:MouseListene

c++ - 线程错误 : invalid use of non-static member function

这个问题在这里已经有了答案:Passingmemberfunctionstostd::thread[duplicate](2个答案)关闭5年前。我想了解C++中的线程,但我不知道如何解决这个问题。我想调用两个线程来运行名为“createS”的函数,但出现此错误:error:invaliduseofnon-staticmemberfunction我读过关于这个主题的其他问题,但我真的不明白如何让我的代码工作。有人可以向我解释我做错了什么并尝试帮助我找到解决方案吗?test_class.cppvoidtest_class::generateS(){map1=newmultimap>;map