Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why virtual void test()=00 is valid but virtual void test()=+0 and virtual void test()=-0 is not valid?

Tags:

c++

syntax

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?

like image 977
ggrr Avatar asked Feb 09 '23 18:02

ggrr


1 Answers

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.

like image 199
Sinkingpoint Avatar answered Feb 13 '23 02:02

Sinkingpoint