C ++中的从简单到复杂的回调. [英] Simple to Complex callback in C++.

查看:116
本文介绍了C ++中的从简单到复杂的回调.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是实现一些代码,并且我似乎无法使回调正常工作.看起来应该如此,但是我收到``错误C2064:术语未评估为带有0个参数的函数''.当它很明显确实需要x个参数时.只需用几行代码即可.

class who {
public:
	void peace();
	void war();
	void negotiator(void (who::*talk)(void) );
};
void who::peace() { 
	printf("Peace! "); 
}
void who::war() { 
	printf("WAR!!! ");
	this->negotiator(&who::peace);
}
void who::negotiator(void (who::*talk)(void) ) {
	talk();
}
int main() {
	who w;
	w.war();
	return 0;
}

我在这里缺少什么?

推荐答案

您正在将指向成员函数的指针传递给谈判者.
You are passing a pointer to a member function to negotiator.
因此,您必须像调用成员函数的指针一样调用它,而不是像普通成员函数那样调用它.
So you must call it like a pointer to a member function and not like an ordinary member function.


这篇关于C ++中的从简单到复杂的回调.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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