Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your description matches perfectly with the case of an abstract class. Declare your virtual function as:</p> <pre><code> virtual void VirtualFunction () = 0; </code></pre> <p>This means that you are not implementing the function in this class. As a result, the class becomes abstract. That is, no bare objects of this class can be instantiated.</p> <p>Also, you should provide a virtual destructor.</p> <p><strong>Update:</strong> Some clarifications...</p> <p>The language allows you to redefine a non-virtual function. Though, the wrong version might be called in some cases:</p> <pre><code>derived D; // rB is a reference to base class but it base &amp; rB=D; // points to an object of the derived class rB.NonVirtualFunction (); // The base-class version is called </code></pre> <p>For this reason, redefining a non-virtual function is strongly discouraged nowadays. See Scott Meyers' "Effective C++, Third Edition: 55 Specific Ways to Improve Your Programs and Designs", item 36: "Never redefine an inherited non-virtual function."</p> <p>See also item 7: "Declare destructors virtual in polymorphic base classes". An example:</p> <pre><code>base * pB = new derived; delete pB; // If base's destructor is not virtual, // ~derived() will not be called. </code></pre> <p>In case you wonder why isn't everything virtual by default, the reason is that calling a virtual function is slightly slower than calling a non-virtual one. Oh, and objects of classes with virtual functions occupy a few more bytes each.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    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