Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are virtual method not "delete"able in C++0x?

Tags:

c++

c++11

virtual

The error message seems to be little mis-leading with the scenario, when we try to delete a virtual method.

prog.cpp:4:16: error: deleted function 'virtual void Test::foo()'
prog.cpp:8:2: error: used here

Code

struct Test : public Base
{
  Test() {}
  virtual void foo () = delete;  // error
};

Are virtual method not deleteable for the same reason, why they cannot remain unimplemented in C++03 ? Is there any way to mention that Test purposely not implementing virtual foo() ?

like image 341
iammilind Avatar asked Dec 04 '22 21:12

iammilind


1 Answers

The term use has a concrete definition in the standard, and in particular for virtual functions the definition of odr-used is:

§3.2/2 (C++0x FDIS) [...]A virtual member function is odr-used if it is not pure.[...]

Where odr-used is a new term in the upcoming standard that refers to what the previous standard called plainly used:

§3.2/2 (current standard) [...]A virtual member function is used if it is not pure.[...]

My take is that the error message employs the term used to refer to odr-used in this particular case, and yes, the reason why this is a violation is exactly the same reason by which you cannot leave a non-pure virtual member function unimplemented.

like image 152
David Rodríguez - dribeas Avatar answered Jan 03 '23 16:01

David Rodríguez - dribeas