gpt4 book ai didi

c++ - 比较函数指针

转载 作者:IT老高 更新时间:2023-10-28 22:37:51 24 4
gpt4 key购买 nike

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

例如,这样的事情是否有效:

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

最佳答案

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

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).

强调我的。

关于c++ - 比较函数指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12898227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com