title: c++ Setting a pointer variable in parent class from child and use it in parent class
body: <p>i'm sorry for the title. I seem to have a problem. I'm just a beginner and i'm sorry if this was asked before.. i couldnt find a straight answer on this one. (when i search class, pointer and child i get results about passing parent or child pointers... i do not want to pass the (this) child or parent pointer, i just want to pass a pointer i initialized on a child class.. to the parent). What i'm trying to do here is better explained by code:</p>
  
  <pre><code>class App
  {
  public:
      virtual void init(void)         { window = &amp;BasicWindow(); }
      virtual void createWindow(void) { window-&gt;create(); }
  
  protected:
      Window *window;
  };  
  
  class Game : public App
  {
  public:
      virtual void init(void)         { window = &amp;OpenGLWindow(); }
  };
  
  int main ()
  {
      App *game = &amp;Game();
      game-&gt;init();
      game-&gt;createWindow();
      return 0;
  }
  </code></pre>
  
  <p>Is this legal? 
  I have an abstract Window class from which BasicWindow and OpenGLWindow derives. 
  However, when i create the window i get an <code>Access violation reading location</code> error breaking at <code>window-&gt;create()</code> inside the <code>App::createWindow()</code> function.</p>
  
  <p>Thanks</p>