This is just how the grammar is defined, if we look at the draft C++ standard section 9.2
Class members the relevant grammar is as follows:
[...]
member-declarator:
declarator virt-specifier-seqopt pure-specifieropt
[...]
pure-specifier:
= 0
^^^
The grammar specifically indicates that a pure-specifier is = 0
and not an integer literal or expression, that does not seem to leave any wiggle room. If I attempt things like:
virtual void foo() = 0L;
or:
virtual void foo() = NULL ;
gcc
tells me:
error: invalid pure specifier (only '= 0' is allowed) before ';' token
and clang
says:
error: initializer on function does not look like a pure-specifier
Although the following does work in both:
#define bar 0
//...
virtual void foo() = bar;
It also seems like clang
allows octal literal, hexadecmical literal and binary literal zero which is incorrect behavior.
Update
Apparently Visual Studio
accepts NULL
and any zero integer literal including 0L
, 0x0
, 00
etc... Although it does not accept nullptr
.
= nullptr
or= abstract
syntax better. – Marlenmarlena