title: What could cause an invalid function reference when calling virtual base functions?
body: <p>I have tried to debug a segfault in my application, but can not figure out what the problem is. It would be too complex to post the full code, so I tried to break down the problem into a simpler version - only to figure out that my basic example works flawlessly.</p>
  
  <p>However, I am still stuck trying to run my application and would appreciate any input on the following - very helpful - error:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x00007fffdd921f38 in main_arena () from /lib/libc.so.6
  </code></pre>
  
  <p>This occurs, when I try to call <code>getType()</code> along these lines:</p>
  
  <pre><code>std::map&lt;long, QVAbstractElement *&gt; mElements;
  
  &lt;...&gt;//skipping some stuff
  
  LineElement * insert_el = new LineElement();
  mElements[0] = insert_el;
  
  &lt;...&gt;//skipping a lot more stuff
  
  AbstractElement * el = mElements.at(0);
  
  if (!el)
  {
      printf("ERROR");
      return (1);
  }
  
  int t = el-&gt;getType();
  </code></pre>
  
  <p>In this case, I know that the pointer <code>el</code> is valid, but the actual object is a <code>LineElement</code>, which was derived from <code>AbstractElement</code> and <code>getType()</code> is a <code>virtual</code> function only implemented in the base class (<code>AbstractElement</code>). When debugging with gdb I get the following pointer address:</p>
  
  <pre><code>(gdb) x el
  0x11cf600:  0xdd921f48
  (gdb) p el
  $1 = (class AbstractElement *) 0x11cf600
  </code></pre>
  
  <p>Now, when trying to call that function (<code>getType</code>) from gdb, I get the following and :</p>
  
  <pre><code>(gdb) x el-&gt;getType()
  warning: can't find linker symbol for virtual table for `AbstractElement' value
  warning: can't find linker symbol for virtual table for `AbstractElement' value
  </code></pre>
  
  <p>Essentially, I think that even though my pointer check works and the address is still the same compared to time of creating this object, I can not call any of this object's functions.</p>
  
  <p><strong>FIRST QUESTION</strong>: Could this have anything to do with calling from different threads - I am using Qt for my UI and not 100% sure if Qt might be creating it's own threads?</p>
  
  <p><strong>SECOND QUESTION</strong>: Does this might actually just mean the problem could be anywhere in my code and this is just a messed up function table as the result?</p>