title: Forward Declaration: Undefined Class ( C2079 )
body: <p>I have an error in my code. All the forums says "in this situation, use Forward Declaration". I tried this and it don't work.</p>
  
  <p>the error is <strong>C2079</strong> Credit::mainMenu use a class of MainMenu not declared (translated from french)</p>
  
  <p>I modified the classe to be specific to the question.</p>
  
  <p><strong><code>main.cpp</code></strong></p>
  
  <pre><code>#include &lt;SFML/Graphics.hpp&gt;
  
  #include "Menu.h"
  
  #include "credit.h"
  #include "mainmenu.h"
  
  
  MainMenu *mainMenu = new MainMenu();//works here
  
  int main(){
      return 0;
  }
  </code></pre>
  
  <p><strong><code>credit.h</code></strong></p>
  
  <pre><code>#ifndef DEF_CREDIT
  #define DEF_CREDIT
  
  #include &lt;SFML/Graphics.hpp&gt;
  #include "Menu.h"
  class MainMenu;
  
  
  class Credit : public Menu
  {
  private:
      MainMenu mainMenu = MainMenu();//DON'T WORK HERE
  };
  
  #endif
  </code></pre>
  
  <p><strong><code>mainmenu.h</code></strong></p>
  
  <pre><code>#ifndef DEF_MAINMENU
  #define DEF_MAINMENU
  
  #include &lt;SFML/Graphics.hpp&gt;
  #include "Menu.h"
  #include "credit.h"
  
  class MainMenu :public Menu
  {
  private:
      Credit credit = Credit();//work
  };
  #endif
  </code></pre>
  
  <p>Fist i load main.cpp
  after the <code>credit.h</code> (there is a <code>credit.hpp</code> but i don't use the variable now)
  after the <code>mainmenu.h</code> (there is also a <code>mainmenu.hpp</code>, i don't use variable now)</p>
  
  <p>tip: the <code>Menu</code> class isn't including any of those class</p>
  
  <p>I can send you the complete code if you want</p>
  
  <p>Thanks in advence!</p>