Namespaces
Variants
Views
Actions

Talk:cpp/language/virtual

From cppreference.com

For the second example, there is a ";" that causes problem

   void f() { do_f(); }; // public interface
problem being the -Wextra-semi warning? Fixed anyway, thanks --Cubbi (talk) 11:21, 6 February 2017 (PST)

[edit] (Relatively easy:) Questions left unanswered in the virtual destructor section

In the virtual destructor section it covers that:

  • if a class has a virtual destructor then any class extending it shall have it's destructor virtualised.

It is unclear what happens if that class is then extended again, or in some of the nastier situations multiple inheritance gives rise to.

I use this site to confirm things (regarding the standard being on my side) and to clarify exotic situations which sometimes come to mind - this is why I feel it is worthwhile to add.

I've marked this as relatively easy because compared to some of the pages on concepts and templates and the like, it certainly is.

Lastly (to prevent anyone wasting their time) please know I'm not a noob, and I am not asking why the standard went the way it did; but I don't object to a comment like what follows being added to the page.

  • Ultimately creating an instance of any class involves creating an instance of exactly 1 class, so the compiler has a clear picture of the class's entire derivation and in implementations using vtables can construct a vtable placing the class's destructor into any relevant entries and ensure the classes destructor acts correctly. If the compiler should lack this information, then it is an error.

Thanks for your time now and both in maintaining this site, and death to cplusplus.com!

Alec (talk) 04:36, 4 April 2018 (PDT)