This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Template argument (pointer to member function) initialization with NULL
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "vagran.ast" <vagran dot ast at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 14 Nov 2011 21:28:01 +0000
- Subject: Re: Template argument (pointer to member function) initialization with NULL
- References: <4EC1789A.2070209@gmail.com>
On 14 November 2011 20:22, vagran.ast wrote:
> Hi,
>
> In the following code:
>
> class A {
> public:
> ? ?void SomeMethod() { }
> };
>
> template <class T, void (T::*SomeMethod)() = 0>
> class B {
>
> };
>
> B<A> b1; // error: could not convert template argument '0' to 'void
> (A::*)()'
>
> B<A, 0> b2; // error: could not convert template argument '0' to 'void
> (A::*)()'
>
> void (A::*someMethod)() = 0; // OK
>
> there are two compilation errors. AFAIK per C++ standard 0 is a valid value
> for a pointer to member
> function. Variable of such type can be successfully initialized by 0 but
> template arguments can not.
> Is it desired behavior or a bug?
I think G++ is correct, you need to cast the literal zero to the right
type to prevent it being treated as an int in that context, or use
C++11's nullptr.