dimanche 5 avril 2015

Are pointers to virtual member functions comparable?


Vote count:

0




I read an article saying



A member function pointer can be set to 0, and provides the operators == and !=, but only for member function pointers of the same class.



I'm trying to understand C++11, §5.10.


In §5.10/1 it says



Pointers of the same type (after pointer conversions) can be compared for equality.



In §5.10/2 it says



Otherwise if either is a pointer to a virtual member function, the result is unspecified.



Now consider the following test program.



#include <cassert>

class ISomeClass
{
public:
virtual ~ISomeClass() {}

virtual void a() = 0;
virtual void b() = 0;
};

int main()
{
typedef void(ISomeClass::*MemberPtr)();

MemberPtr mp = &ISomeClass::a;

assert( mp == &ISomeClass::a );
assert( mp != &ISomeClass::b );

return 0;
}


Are the asserts true or unspecified according to the standard?



asked 52 secs ago







Are pointers to virtual member functions comparable?

Aucun commentaire:

Enregistrer un commentaire