title: Linker error on pure virtual function call with gcc
body: <p>A friend and I had a very interesting discussion about the construction of Objects that ended up with this piece of code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Parent {
    public:
      Parent( ) {
        this-&gt;doSomething( );
      }
  
      virtual void doSomething( ) = 0;
  };
  
  class Child : public Parent {
      int param;
  
    public:
      Child( ) {
        param = 1000;
      }
  
      virtual void doSomething( ) {
        std::cout &lt;&lt; "doSomething( " &lt;&lt; param &lt;&lt; " )" &lt;&lt; std::endl;
      }
  };
  
  int main( void ) {
      Child c;
      return 0;
  }
  </code></pre>
  
  <p>I know that the standard does not define the behavior when a pure virtual function is called  from a constructor or destructor, also this is not a practical example of how i would write code in production, it is just a test to check what the compiler does. </p>
  
  <p>Testing the same construct in Java prints </p>
  
  <blockquote>
    <p>doSomething( 0 )</p>
  </blockquote>
  
  <p>That makes sense since <code>param</code> is not initialized at the point <code>doSomething()</code> is called from the parent constructor. </p>
  
  <p>I would expect similar behavior in C++, with the difference that <code>param</code> contains anything at the time the function is called. </p>
  
  <p>Instead compiling the above code results in a linker error with <code>(c++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3)</code> saying that the reference to <code>Parent::doSomething( )</code> is undefined.</p>
  
  <p>So, my question is: <strong>Why is this a linker error?</strong> If this is an error, I would expect the compiler to complain, especially because there is an implementation of the function.
  Any insight of how the linker works in this case or a reference to further reading would be highly appreciated.</p>
  
  <p>Thank you in advance! I hope that this question is not a duplicate, but i could not find a similar question..</p>