title: C++ in G++ - Segmentation Fault when not using pointers
body: <p>I'm trying to use G++ to compile some C++ code. It seems to work fine in other compilers, but for whatever reason, G++ won't produce working output.</p>
  
  <p><strong>Disclosure:</strong> This is part of a homework assignment, but I feel like it's more of a compiler issue, since it works in other compilers.</p>
  
  <p>Here's the snippet that's wreaking havoc:</p>
  
  <pre><code>set&lt;int&gt; t1, t2;
  </code></pre>
  
  <p>It's strange because the following code works just fine:</p>
  
  <pre><code>set&lt;int&gt; *t1 = new set&lt;int&gt;();
  set&lt;int&gt; *t2 = new set&lt;int&gt;();
  </code></pre>
  
  <p>Granted, I have to use <code>-&gt;</code> instead of <code>.</code>, but that's expected. The first snippet produces a segmentation fault at runtime. The second does intuitively what I'd expect it to.</p>
  
  <p>Anyhow, behind the scenes, the <code>.cpp</code> for <code>set</code> has this:</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  template &lt;class T&gt;
  set&lt;T&gt;::set() : bag&lt;T&gt;() {}
  
  template &lt;class T&gt;
  set&lt;T&gt;::set(const set&lt;T&gt;&amp; b) : bag&lt;T&gt;(b) {}
  </code></pre>
  
  <p>The <code>.h</code> looks like this:</p>
  
  <pre><code>#include "bag.h"
  
  template &lt;class T&gt;
  class set : public bag&lt;T&gt;
  { 
      public:
          set( );
          set(const set &amp;b);
  
  // ...
  
  };
  #include "set.cpp"
  </code></pre>
  
  <p>And last but not least, the <code>bag.cpp</code> and <code>bag.h</code> files looks like this:</p>
  
  <pre><code>using namespace std;
  
  template &lt;class T&gt;
  bag&lt;T&gt;::bag() {
      head = NULL;
  }
  
  template &lt;class T&gt;
  bag&lt;T&gt;::bag(const bag&lt;T&gt;&amp; b) {
  
      // ...
  
  }
  </code></pre>
  
  <p>and <code>bag.h</code>:</p>
  
  <pre><code>template &lt;class T&gt;
  class bag
  { 
      public:
          bag( );
          bag(const bag &amp;b);
  
      // ...
  };
  #include "bag.cpp"
  </code></pre>
  
  <p>Again, I feel like G++ just hates me, but then again I could be doing something dumb. Just a simple nudge in the right direction would be great.</p>