Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange error message when a class method is missing
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/1095298/gcc-c-linker-errors-undefined-reference-to-vtable-for-xxx-undefined-referen">GCC C++ Linker errors: Undefined reference to &#39;vtable for XXX&#39;, Undefined reference to &#39;ClassName::ClassName()&#39;</a> </p> </blockquote> <p>I have been banging my head against a wall for a long time because of a strange ld error. So I reproduced it in a small test case to understand the issue.</p> <p>I declared a class and I derived another one in a header file:</p> <pre><code>class BaseClass { public: BaseClass(){}; virtual void func(){}; }; class DerivedClass: public BaseClass { public: DerivedClass(); void func(); }; </code></pre> <p>Then I defined the constructor but forgot to define <code>func</code> (voluntary here, but that actually what I did with a silly copy/paste...):</p> <pre><code>DerivedClass::DerivedClass(){ cout &lt;&lt; "Derived constructor" &lt;&lt; endl; } //void DerivedClass::func(){ // cout &lt;&lt; "Derived func" &lt;&lt; endl; //} </code></pre> <p>Then I get:</p> <blockquote> <p>undefined reference to `vtable for DerivedClass'</p> </blockquote> <p>Edit: And the message points the declaration of the consctructor!</p> <p>If I uncomment the definition of <code>func</code>, then I have no error. So my question: Why does the linker didn't tell me that the definition of <code>func</code> is missing?</p> <p>The solution might be obvious when you are experienced, but for a beginner like me it's not!</p> <p>Thanks for your help.</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.
 

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