Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you have 2 problems here: The first is that you are using include guards in your source files; the second is that the order in which you have included your files is wrong.</p> <p>First, include guards. Others have answered this question already, so I'll be brief. Include guards are used only in header files in order to prevent classes/types being declared more than once. For example if I had:</p> <p><strong>"game.h"</strong>:</p> <pre><code>class Game {}; </code></pre> <p><strong>"game.cpp"</strong>:</p> <pre><code>#include "game.h" #include "game.h" // ERROR: class Game is declared twice. </code></pre> <p>To fix this I would use include guards in "game.h":</p> <pre><code>#ifndef GAME_H_INCLUDED #define GAME_H_INCLUDED class Game {}; #endif </code></pre> <p>The first time the file is included, GAME_H_INCLUDED is not defined, so Game is declared. The second time it is include, GAME_H_INCLUDED <em>is</em> defined, so the declaration is skipped.</p> <p>The problem you have is that your include guards in you source files will cause all of the implementation to be skipped:</p> <p><strong>broken "game.cpp"</strong>:</p> <pre><code>#include "game.h" #ifndef GAME_H_INCLUDED // This is defined in "game.h" so everything will be // skipped until #endif is encountered. #define GAME_H_INCLUDED // Implementation of Game class #endif </code></pre> <p>Second, the order in which you are including headers is incorrect. I'm guessing you have something like this:</p> <p><strong>"game.h"</strong></p> <pre><code>#ifndef GAME #define GAME class Game { Date mDate; // Member of type Date, declared in "date.h" }; #endif </code></pre> <p><strong>"date.h"</strong></p> <pre><code>#ifndef GAME #define GAME class Date { }; #endif </code></pre> <p><strong>"game.cpp"</strong></p> <pre><code>#include "game.h" // ERROR: Game relies on the Date class, // which isn't included yet #include "date.h" </code></pre> <p>To fix this either swap the order of the includes in "game.cpp":</p> <p><strong>"game.cpp"</strong></p> <pre><code>#include "date.h" #include "game.h" // Fine, we know what a Date is now. </code></pre> <p>Or include "date.h" in "game.h":</p> <p><strong>"game.h"</strong></p> <pre><code>#include "date.h" #ifndef GAME #define GAME class Game { Date mDate; // Member of type Date, declared in "date.h" }; #endif </code></pre> <p><strong>"game.cpp"</strong></p> <pre><code>#include "game.h" // Still fine, "date.h" is included by "game.h" </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload