title: GDB incomplete type when having C++ virtual function
body: <p>I have just noticed something weird, when I add the "virtual keyword" in my class (any function except the constructor), I can't display the content of my object in GDB. GDB says "incomplete type"</p>
  
  <p>Here is the code :</p>
  
  <p>//////////////// reco.h /////////////</p>
  
  <pre><code>#ifndef RECO_H
  #define RECO_H
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  class reco {
      public:
          reco(float weight);
          ~reco(void);
  
          float getWeight();
  
      private:
          float weight;
  };
  
  #endif
  </code></pre>
  
  <p>///////////////// reco.cpp /////////////</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  #include "reco.h"
  
  using namespace std;
  
  reco::reco(float weight) {
      weight = weight;
  }
  
  reco::~reco(void) {
      cout &lt;&lt; "destructor reco" &lt;&lt; endl;
  }
  
  float reco::getWeight() {
      return weight;
  }
  </code></pre>
  
  <p>////////////// main.cpp /////////////</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  #include "reco.h"
  
  using namespace std;
  
  
  int main() {
      reco* s = new reco(5.0);
      cout &lt;&lt; s-&gt;getWeight() &lt;&lt; endl;
  
      delete s;
  
      return 0;
  }
  </code></pre>
  
  <p>Then with GDB :</p>
  
  <pre><code>gdb main.exe
  breakpoint main.cpp:11 &lt;---- (cout)
  run
  print *s
  $1 = { weight = 5 }
  </code></pre>
  
  <p>And then, if I make one of the functions "virtual", and I retry to print my <code>*s</code> pointer with GDB, it says: 
  "incomplete type"</p>
  
  <p>It looks like there is something happening with the VTABLE, as if the "virtual" keyword was hiding the implementation of my Reco class. I know that the compiler does late binding and then, the VTABLE lookup is done at runtime, but the program is already running while GDB is debugging it, right ?</p>
  
  <p>The "set print vtbl" setting in "on".</p>
  
  <p>If I use <code>ptype s</code>, I get the <code>&lt;incomplete type&gt;</code> message again.</p>
  
  <p>If I examine the address with <code>x/540f80</code>, it says "cannot access memory"</p>
  
  <p>I don't know why just adding this keyword makes my object's type incomplete ?</p>
  
  <p>Thanks a lot for your help !</p>
  
  <p>One last thing that I notice :</p>
  
  <p>WITH VIRTUAL:</p>
  
  <pre><code> reco.cpp -&gt; g0 and main.cpp -&gt; g = incomplete type
   reco.cpp -&gt; g and main.cpp -&gt;g = ok
  </code></pre>
  
  <p>WITHOUT VIRTUAL</p>
  
  <pre><code> reco.cpp -&gt; g0 and main.cpp -&gt; g = ok
   reco.cpp -&gt; g and main.cpp -&gt;g = ok
  </code></pre>