title: Memory violation: SIGSEGV and 'can't find linker symbol for virtual table...'
body: <p>I struggle with a memory violation error in my C++ code, and it makes me crazy. I have to use some existing classes and they work fine almost everywhere else. </p>
  
  <p>I am trying to make a copy of a custom Array object, than modify inner values later. But there is something wrong with that copy operation...</p>
  
  <p>The symptoms are the following:</p>
  
  <ul>
  <li><p><code>Segmentation fault</code> after the copy, but not immediately </p></li>
  <li><p>Warning: <code>can't find linker symbol for virtual table for 'MyClass&lt;T&gt;' value</code></p></li>
  </ul>
  
  <p><code>MyClass&lt;T&gt;</code> has nothing to do with the problematic part, and after searching I found that this error could appear when the <strong>vtable was overwritten</strong> <a href="https://stackoverflow.com/questions/8695411/warning-cant-find-linker-symbol-for-virtual-table-for-value-xxx-value-using">(link)</a>.</p>
  
  <p>The SIGSEGV appears at the end of this snippet:</p>
  
  <pre><code>// New boxes based on previous content, so first make a copy
  Array&lt;Box&gt; nextBoxes(size);
  int ic = followingItems.length();  // Array&lt;int&gt; followingItems() : some item id
  for (int b = 0; b &lt; size; ++b) {
      Box box(ic, capacity);
      const Box&amp; oBox = currentBoxes[b];  // Array&lt;Box&gt; currentBoxes(size);
      for (int i = 0; i &lt; ic; ++i) {
          if (oBox[i])
              box.add(i);
      }
      nextBoxes.add(box);
  }
  
  createConfig(nextBoxes, nextItems);
  ...
  generateCostMatrix(nextBoxes, costMatrix); // &lt;--[SIGSEGV] without any reason, variables are fine
  </code></pre>
  
  <p>And that's where I am totally lost. I tried to use <code>std::vector</code> instead <code>Array&lt;Box&gt; nextBoxes</code> but the problem remained, just appeared at a different location.</p>
  
  <p>Here is one from the 'legacy' classes:</p>
  
  <pre><code>class Box 
  {
      Array&lt;bool&gt; items;  // mask of all tools
      int capacity, itemCount, count;
  public:
      Box();
      Box(int num, int cap)
        : items(num), capacity(cap), itemCount(num), count(0)
      {
          for (int i = 0; i &lt; num; i++)
              items.add(false);
      }
      Box(const Box&amp; value){...}
      ~Box(){...}
      ...
  </code></pre>
  
  <p>A tiny debugger info from the crash location:</p>
  
  <pre><code>array = new T[maxlen]
  // values: array=0x0, maxlen=30, len=0 --&gt; looks OK
  </code></pre>
  
  <p>(somewhere deep in the <code>Array&lt;T&gt;</code> class, it doesn't really matter where, because always happens in the line <code>new</code> like here, and always without visible reason)</p>