模板 + Boost::Function。示例代码:

#include <string>
#include 
<iostream>
#include 
<boost/function.hpp>

using namespace std;
using namespace boost;

class Test
{
public:
    Test(){};
    
virtual ~Test(){};
    
    
void Handle(string& s, unsigned int lines)
    {
        
for(int i=0; i< lines; i++)
        {
            cout 
<< s << endl;
        }
    };
};

template 
<class T>
static void CallBack(T& t, boost::function<void (T*string&, unsigned int)> f)
{
    
string s("test");
    f(
&t, s, 3);
};

int main()
{
    Test test;
    CallBack
<Test>(test, &Test::Handle);
    
return 0;
}

相关文章:

  • 2021-06-04
  • 2021-11-02
  • 2021-09-10
  • 2021-06-21
  • 2021-11-30
  • 2021-08-14
  • 2021-12-24
猜你喜欢
  • 2021-11-02
  • 2022-01-10
  • 2022-01-12
  • 2021-12-02
  • 2021-07-10
相关资源
相似解决方案