比较函数指针 [英] Comparing function pointers

查看:93
本文介绍了比较函数指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何比较C ++中的函数指针?是否稳定?

How can I compare function pointers in C++? Is it stable?

例如,这样是否有效:

if(pFnc == &myFnc){
//Do something
}


推荐答案

C ++ 03 5.10 / 1 [expr.eq]:



C++03 5.10/1 [expr.eq]:


==(等于)和!=(不等于)运算符具有与关系
运算符相同的
语义限制,转换和结果类型,除了它们的较低优先级和真值结果。
[注意:a< b
== c< d为真, b和c < d具有相同的真值。 ] 指向相同类型的对象或函数的指针(在指针转换后)可以比较为相等。同一个
类型的两个指针比较等于当且仅当它们都为空,都指向
同一个函数,或者两者都表示相同的地址(3.9.2)。

The == (equal to) and the != (not equal to) operators have the same semantic restrictions, conversions, and result type as the relational operators except for their lower precedence and truth-value result. [Note: a < b == c < d is true whenever a < b and c < d have the same truth-value. ] Pointers to objects or functions of the same type (after pointer conversions) can be compared for equality. Two pointers of the same type compare equal if and only if they are both null, both point to the same function, or both represent the same address (3.9.2).

强调我。

这篇关于比较函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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