C++ Inheritance Problem leads to segmentation fault
<p>Here is some sample code to illustrate the problem I am having.</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

class Foo
{
    public:
        Foo(int x)
        { m_x = x; }
        int getX()
        { return m_x; }
    private:
        int m_x;
};

class Bar : public Foo
{
    public:
        Bar(int x) : Foo(x)
        {}
        //some other stuff
};

int main()
{
    Bar* bar = new Bar(5);
    cout&lt;&lt;bar-&gt;getX()&lt;&lt;endl;
    return 0;
}
</code></pre>

<p>I have a large project that I am working on and I have a similar situation to above. When bar->getX() is called the this pointer is 0x0 causing a segmentation fault. I have tried copping the getX function to the Bar class but this does not fix the problem, the this pointer is still 0x0. Any ideas? I have no idea how to google for this, only found people having problems with virtual functions.</p>

<p>ps. This sample works.</p>

<h1>EDIT:</h1>

<pre><code>std::cout&lt;&lt;m_engine&lt;&lt;std::endl;
focus_x = m_engine-&gt;getX(); 
</code></pre>

<p>The output is:0x2e6d763638667858 (not NULL), so that is not the problem...</p>
