4

I searched some post about virtual function declaration, which believed

=0

in

virtual void test()=0;

is fixed syntex so

virtual void test()=NULL;
virtual void test()=false;
virtual void test()=1-1;
virtual void test()=0.0;

and other declarations should not be valid.

but I found

virtual void test()=00;
virtual void test()=000;
virtual void test()=0000;

can also compile, why?

and also, I think integer +0 and -0 are actually same as 0 (I am not sure if it is right), just like 00 is actually 0, why

virtual void test()=+0;

and

virtual void test()=-0;

cannot compile?

ggrr
  • 7,737
  • 5
  • 31
  • 53

3 Answers3

4

The pure-specifier is the exact token sequence = 0 - two tokens, = and 0, in that order.

No other token is allowed. A compiler that accepts =00 without (at the very least) a warning is non-conforming.

T.C.
  • 133,968
  • 17
  • 288
  • 421
4

From the November 2014 working draft of the standard:

10.4:

A virtual function is specified pure by using a pure-specifier (9.2) in the function declaration in the class definition.

In 9.2 we see the definition of a "pure-specifier":

pure-specifier: = 0

This shows that your examples should not compile, as you expect and as such you should file a bug report with your compiler manufacturer.

Community
  • 1
  • 1
Sinkingpoint
  • 7,449
  • 2
  • 29
  • 45
0

In my opinion, it is simply because compiler (or some pre-compilation process) is replacing set of zeros with single zero. Excel and Calc.exe, for example replaces 0000 with 0.

Ajay
  • 18,086
  • 12
  • 59
  • 105