This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
using member templates to cast 0 to pointer to member fun...
- To: egcs at egcs dot cygnus dot com
- Subject: using member templates to cast 0 to pointer to member fun...
- From: adriang at campbellsoft dot com
- Date: Fri, 18 Dec 1998 13:07:55 -0600
Subject: using member templates to cast 0 to pointer to member function
Scott Meyers, in 'Effective C++ second edition 50 Specific Ways to improve
your programs and design' mentions at page 112 an implementation for a class
that uses member templates to cast 0 to any kind of pointer. Now, I'm using
egcs-2.91.60 (release 1.1.1) on the following code:
const class Null
{
public:
Null() {}
template<class T>
operator T* () const
{ return static_cast<T*>(0); }
template<class C, class T>
operator T C::* () const
{ return static_cast<T C::*>(0); }
} NULL;
class a
{
public:
int bingo(int){}
};
typedef int (a::*PFNBINGO)(int);
void main(void)
{
PFNBINGO pfn = &a::bingo;
PFNBINGO pfnBingo = NULL:
}
everything works fine, until assigning NULL to the member function pointer.
the error is:
cannot convert `NULL' from type `Null' to type `int (a::*)(int)'
funny is that egcs-2.91.60 manages to cast my NULL to a member pointer, as
long as it is not a member function pointer.
Am I missing anything in the standard, am I missing anything in the way I
write the code, or it is something that still needs work in egcs??
thanx
adrian