回调到非静态方法? [英] Callback to a non-static method?

查看:71
本文介绍了回调到非静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




(我希望这不是常见问题解答)


我正试着打电话给定时器对象的方法。


void MyClass :: myCallback(int par)

{cout<< Call Call Called << std :: endl;}


void MyClass :: addTimer()

{

signal(SIGALRM,myCallback); < br $>
// ...

}


这不起作用。错误是

类型'的参数''void(MyClass ::)(int)''与''无效(*)(int)''"


为什么这不起作用?有解决方法吗?


谢谢,

Levin

Hi,

(I hope that this is not a FAQ)

I''m trying to make a timer call a method of an object.

void MyClass::myCallback(int par)
{cout << "Callback Called" << std::endl;}

void MyClass::addTimer()
{
signal(SIGALRM, myCallback);
// ...
}

This does not work. The Error is
"argument of type ''void (MyClass::)(int)'' does not match ''void (*)(int)''"

Why is that not working? Is there a workaround?

Thanks,
Levin

推荐答案

* 莱文亚历山大 <乐*** @ grundeis.net> schriebt:
* "Levin Alexander" <le***@grundeis.net> schriebt:

我正在尝试将定时器调用为对象的方法。

void MyClass :: myCallback(int par)
{cout<< Call Call Called << std :: endl;}

void MyClass :: addTimer()
{
信号(SIGALRM,myCallback);
// ...
}

这不起作用。错误是
类型的参数'void(MyClass ::)(int)''与''void(*)(int)''"

I''m trying to make a timer call a method of an object.

void MyClass::myCallback(int par)
{cout << "Callback Called" << std::endl;}

void MyClass::addTimer()
{
signal(SIGALRM, myCallback);
// ...
}

This does not work. The Error is
"argument of type ''void (MyClass::)(int)'' does not match ''void (*)(int)''"




很高兴您遇到编译错误,因为混合C信号和C ++

面向对象的代码根本不受支持,并导致UB。

因此技术错误阻止你制造更严重的

并且更难以确定错误。


很多其他人可能会解释如何使用Technical Thing(TM)

来编译代码(从而引入Grave Error(TM))。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么顶级发布这么糟糕的事情?

答:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



Be glad you got a compilation error, because mixing C signals and C++
object-oriented code is simply not supported, and leads to UB.

So the technical error prevented you from making a much more serious
and much more difficult to pin down error.

Many others will probably explain how to do The Technical Thing (TM)
to get the code to compile (thus introducing the Grave Error (TM)).

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


*Levin Alexander ; <乐*** @ grundeis.net> schriebt:
* "Levin Alexander" <le***@grundeis.net> schriebt:

我正在尝试将定时器调用为对象的方法。

void MyClass :: myCallback(int par)
{cout<< Call Call Called << std :: endl;}

void MyClass :: addTimer()
{
信号(SIGALRM,myCallback);
// ...
}

这不起作用。错误是
类型的参数'void(MyClass ::)(int)''与''void(*)(int)''"

I''m trying to make a timer call a method of an object.

void MyClass::myCallback(int par)
{cout << "Callback Called" << std::endl;}

void MyClass::addTimer()
{
signal(SIGALRM, myCallback);
// ...
}

This does not work. The Error is
"argument of type ''void (MyClass::)(int)'' does not match ''void (*)(int)''"




很高兴您遇到编译错误,因为混合C信号和C ++

面向对象的代码根本不受支持,并导致UB。

因此技术错误阻止你制造更严重的

并且更难以确定错误。


很多其他人可能会解释如何使用Technical Thing(TM)

来编译代码(从而引入Grave Error(TM))。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么顶级发布这么糟糕的事情?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



Be glad you got a compilation error, because mixing C signals and C++
object-oriented code is simply not supported, and leads to UB.

So the technical error prevented you from making a much more serious
and much more difficult to pin down error.

Many others will probably explain how to do The Technical Thing (TM)
to get the code to compile (thus introducing the Grave Error (TM)).

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?




Levin Alexander <乐*** @ grundeis.net>在消息中写道

news:op ************** @ news.rwth-aachen.de ...

"Levin Alexander" <le***@grundeis.net> wrote in message
news:op**************@news.rwth-aachen.de...


(我希望这不是FAQ)
Hi,

(I hope that this is not a FAQ)




错误。

http://www.parashift.com/c++ -faq-lit .... html#faq-33.2


john



Err it is.

http://www.parashift.com/c++-faq-lit....html#faq-33.2

john


这篇关于回调到非静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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