public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* using member templates to cast 0 to pointer to member fun...
@ 1998-12-18 12:28 adriang
  1998-12-19 21:52 ` Alexandre Oliva
  0 siblings, 1 reply; 2+ messages in thread
From: adriang @ 1998-12-18 12:28 UTC (permalink / raw)
  To: egcs

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: using member templates to cast 0 to pointer to member fun...
  1998-12-18 12:28 using member templates to cast 0 to pointer to member fun adriang
@ 1998-12-19 21:52 ` Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 1998-12-19 21:52 UTC (permalink / raw)
  To: adriang; +Cc: egcs

On Dec 18, 1998, adriang@campbellsoft.com wrote:

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

It looks like a bug in egcs to me.  I'm installing a testcase based on 
your post in the testsuite.

-- 
Alexandre Oliva  http://www.dcc.unicamp.br/~oliva  aoliva@{acm.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Universidade Estadual de Campinas, SP, Brasil

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-12-19 21:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-18 12:28 using member templates to cast 0 to pointer to member fun adriang
1998-12-19 21:52 ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).