Note that there are some explanatory texts on larger screens.

plurals
  1. POPure virtual functions may not have an inline definition. Why?
    primarykey
    data
    text
    <p>Pure virtual functions are those member functions that are virtual and have the <em>pure-specifier</em> ( <code>= 0;</code> )</p> <p><strong><em>Clause 10.4 paragraph 2</em></strong> of C++03 tells us what an abstract class is and, as a side note, the following:</p> <p><em>[Note: a function declaration cannot provide both a pure-specifier and a definition —end note] [Example:</em></p> <pre><code>struct C { virtual void f() = 0 { }; // ill-formed }; </code></pre> <p><em>—end example]</em></p> <p>For those who are not very familiar with the issue, please note that <strong><em>pure virtual functions can have definitions</em></strong> but the above-mentioned clause forbids such definitions to appear inline (lexically in-class). (For uses of defining pure virtual functions you may see, for example, <a href="http://www.gotw.ca/gotw/031.htm" rel="noreferrer">this GotW</a>)</p> <p>Now for all other kinds and types of functions it is allowed to provide an in-class definition, and this restriction seems at first glance absolutely artificial and inexplicable. Come to think of it, it seems such on second and subsequent glances :) But I believe the restriction wouldn't be there if there weren't a specific reason for that.</p> <p>My question is: does anybody <strong><em>know</em></strong> those specific reasons? <em>Good</em> guesses are also welcome.</p> <p><strong><em>Notes:</em></strong></p> <ul> <li>MSVC does allow PVF's to have inline definitions. So don't get surprised :)</li> <li>the word <code>inline</code> in this question does not refer to the <em>inline</em> keyword. It is supposed to mean <em>lexically in-class</em></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload