相关疑难解决方法(0)

C++ 11 std :: bind和boost :: bind之间的区别

这两者有什么区别吗?还是我的安全,以取代所有出现boost::bindstd::bind在我的代码,从而消除对加速的依赖?

c++ boost boost-bind stdbind c++11

66
推荐指数
4
解决办法
2万
查看次数

将boost :: function降级为普通函数指针

想要将boost :: bind传递给期望普通函数指针(相同签名)的方法.

typedef void TriggerProc_type(Variable*,void*);
void InitVariable(TriggerProc_type *proc);
boost::function<void (Variable*, void*)> triggerProc ...
InitVariable(triggerProc);

error C2664: 'InitVariable' : cannot convert parameter 1 from 
'boost::function<Signature>' to 'void (__cdecl *)(type *,void *)'
Run Code Online (Sandbox Code Playgroud)

我可以避免存储boost :: function并直接传递绑定的functor,但后来我得到类似的错误:

error C2664: 'blah(void (__cdecl *)(type *,void *))' : cannot convert parameter
1 from 'boost::_bi::bind_t<R,F,L>' to 'void (__cdecl *)(type *,void *)'
Run Code Online (Sandbox Code Playgroud)

c++ boost functor

21
推荐指数
2
解决办法
2万
查看次数

无效使用非静态成员函数

我有这样的事情:

class Bar
      {
      public:
        pair<string,string> one;
        std::vector<string> cars;
        Bar(string one, string two, string car);
      };

class Car
      {
      public:
        string rz;
        Bar* owner;
        Car(string car, Bar* p);
      };

class Foo
       {
         public:
          Foo  ( void );
          ~Foo  ( void );
          int Count ( const string & one, const string &  two) const;
          int comparator (const Bar & first, const Bar & second) const;            
            std::vector<Bar> bars;
       };

int Foo::comparator(const Bar & first, const Bar & second) const{
  return first.name < …
Run Code Online (Sandbox Code Playgroud)

c++ const function member non-static

19
推荐指数
3
解决办法
13万
查看次数

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

我正在设置一个成员函数作为我正在使用的C库的回调.C库设置如下的回调:

typedef int (*functionPointer_t)(myType1_t*, myType2_t*, myType3_t*);

setCallback(param1, param2, functionPointer, param4)
Run Code Online (Sandbox Code Playgroud)

我想使用boost :: bind(如果可能的话)传入函数指针.我希望指向的函数是实例化类的成员,而不是静态成员.例如

Class A {
 public: 
  A();
 protected:
  int myCallback(myType1_t*, myType2_t*, myType3_t*); //aka functionPointer_t
}
Run Code Online (Sandbox Code Playgroud)

可以使用boost :: bind和boost :: function来完成吗?Per 如何将类成员函数作为回调传递?(第3个答案)似乎我可以声明以下内容(某处或作为typedef):

boost::function<int (A*, myType1_t*, myType2_t*, myType3*> myCallbackFunction
Run Code Online (Sandbox Code Playgroud)

然后在A(ctor)的某处调用boost :: bind在该类型上,并将其传递给C库调用.

这可能吗,还是我不在基地?非常感谢.

c++ boost boost-bind boost-function

7
推荐指数
1
解决办法
1万
查看次数

如何将C ++类函数作为回调传递

我有一点麻烦了解如何通过这个以被传递到库的回调函数。该功能需要具有特定的签名。

有问题的库是OCILIB(https://vrogier.github.io/ocilib/doc/html/classocilib_1_1_subscription.html),并尝试将类函数作为Register()的第4个参数传递。

我可以顺利通过以下

&database::callback // a static function of database
Run Code Online (Sandbox Code Playgroud)

要么

[](ocilib::Event &event) // as lambda function
{
}
Run Code Online (Sandbox Code Playgroud)

但它无权访问实例变量。我试图像

[&](ocilib::Event &event) // as lambda function
{
}
Run Code Online (Sandbox Code Playgroud)

但签名不匹配,出现以下错误

database.cpp: In member function ‘bool dcn::database::watch(std::__cxx11::string)’:
database.cpp:104:44: error: no matching function for call to ‘ocilib::Subscription::Register(ocilib::Connection&, std::__cxx11::string&, ocilib::Subscription::ChangeTypesValues, dcn::database::watch(std::__cxx11::string)::<lambda(ocilib::Event&)>, unsigned int, unsigned int)’
    }, (unsigned int) 7778, (unsigned int) 0);
                                            ^
In file included from /usr/include/ocilib.hpp:9194:0,
                 from /home/ai/dcn/include/main.h:17,
                 from database.cpp:1:
/usr/include/ocilib_impl.hpp:6650:13: note: candidate: void ocilib::Subscription::Register(const ocilib::Connection&, const ostring&, …
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
83
查看次数

Call SetWindowsHookEx with method defined in header file

I am attempting to add a low level mouse hook to a class. I am able to do so by placing this function in my CPP file:

LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    //my hook code here
    return CallNextHookEx(0, nCode, wParam, lParam);
} 
Run Code Online (Sandbox Code Playgroud)

Then, I set up the hook in the class constructor like so:

HHOOK mousehook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0);
Run Code Online (Sandbox Code Playgroud)

This works fine for intercepting mouse events, however since the callback function is not defined …

c++ windows hook winapi c++builder

0
推荐指数
1
解决办法
3299
查看次数