函数指针成员函数 [英] function pointers member functions
本文介绍了函数指针成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我正在处理类成员函数的函数指针
并且它们被设置为回调等。
然后,被调用。
我的问题是我认为检查函数
指针是否已设置为NULL等是个好主意?对吗?
例如,可能在调用它们之前等等。??
谢谢。
Hello,
I am dealing with function pointers to classes member functions
and they are being set as callbacks etc.
Then, been invoked.
My question is I think it is a good idea to check the function
pointers whether they have been set to NULL etc.? right?
e.g., maybe before invoking them etc.??
Thanks.
推荐答案
在提出问题之前做一些研究总是一个好主意。在过去的几天里有几个关于成员函数指针的问题,这些答案中的任何一个都对你有价值。
关于指针零点检查:下面的句子是如此微不足道,以至于我几乎不敢把它作为一个建议:它从不伤害检查,但也绝不保证指针有效。您应该通过其他方式(正确初始化)确保您的指针(数据指针或成员函数指针等)具有有效值。
当然,您可以使用零值表示成员函数指针当时无效,例如因为到目前为止还没有指定回调。
It is always a good idea to do some research before asking a question. There were a couple of questions about member functions pointers in last few days and any of those answers would have been valuable for you.
Regarding a Zero check on pointers: The following sentence is so trivial that I am almost afraid to give that as an advice: It never hurts to check, but is also never a guarantee that a pointer is valid otherwise. You should make sure by other means (correct initialization) that your pointers (data pointer or member function pointers alike) have a valid value.
Of course, you can use the zero-value is indication that the member function pointer is not valid at the time, for example because no callback has been specified so far.
在你之前检查总是一个好主意调用一个电话。
你可以插入断言来检查调试时间以确保函数不为空
It is always a good idea to check before you invoke a call.
You can insert assert to check on debug time to make sure that function is not empty
这篇关于函数指针成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文