使用在头文件中声明的静态方法的C ++回调函数 [英] C++ callback stuff using static methods declared in header

查看:158
本文介绍了使用在头文件中声明的静态方法的C ++回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hallo社区,我目前在C ++中使用此代码。我想传递一个void方法的引用,所以它可以从另一个类中的另一个方法调用。



Hallo community, i have currently this code in C++. I want to pass the reference of a void method so it can be called from another method in another class.

//main.cpp
#include "A"
void Handler(int val);
void Handler(int val) 
{
  printf("%d", val); //should display 5
}
int main()
{
   A fnc;
   fnc.execute(&Handler); //no matching function for call to (void (::*)(int))|
}
//A.h
public:
void execute(void **something(int val));

//A.cpp
void execute(void **something(int val))
{
   //call Handler()
   something(5);
}





我的尝试:



-------------------------------------------- -----------



What I have tried:

-------------------------------------------------------

推荐答案

在C ++中使用这种技术称为回调。



在这里您可以找到有关回调的教程



作为一个经验丰富的程序员,更喜欢接口,因为从编译器进行类型检查,调试优点和更清晰的概念,如模块化和维护。在这里您可以找到一些有关界面的教程
Using this technique in C++ is named callbacks.

Here you find a tutorial about callbacks.

As an experienced programmer like interfaces more, because type checking from the compiler, debugging adavantages and cleaner concepts like modularity and maintenance. Here you find some tutorial about interfaces.


这篇关于使用在头文件中声明的静态方法的C ++回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆