title: C++ Seg fault on reference to stored base class pointer
body: <p>I'm getting some nasty segmentation faults through the g++ compiler on the following code. Any ideas on why this would happen and how to fix it would be great.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Base {
  public:
    Base() {}
    virtual ~Base() {};
    virtual int getNum(int) = 0;
  };
  
  class Derived: public Base {
  public:
    Derived() :
      Base() {}
    ~Derived() {}
  
    int getNum(int num) {
      return num;
    }
  };
  
  class Foo {
  public:
    Foo() {
    };
    void init() {
      Derived n;
      *baseId = n;
    }
    void otherStuff() {
      cout &lt;&lt; "The num is" &lt;&lt; baseId-&gt;getNum(14) &lt;&lt; baseId-&gt;getNum(15) &lt;&lt; baseId-&gt;getNum(16) &lt;&lt; baseId-&gt;getNum(15) &lt;&lt; endl;
    }
    Derived* baseId;
  };
  
  int main() {
    Foo f;
    f.init();
    f.otherStuff();
    return 0;
  }
  </code></pre>