title: C++ - avoiding a multiple definition creating more problems
body: <p>I am breaking down some code into header and source files and I am having real trouble in avoiding a multiple definition of the array Database.</p>
  <p>I had problems with multiple definitions of Database, which originally looked like this:</p>
  <p><strong>database.h original</strong></p>
  <pre><code>// number of columns in row of the database
  #include &lt;cstdint&gt;
  #define DATABASE_COLS 16
  
  
  int8_t Database[][DATABASE_COLS] = {
     //20x16 integer values are here, removed on StackOverflow for easier reading
  };
  
  
  // number of rows in the database
  #define DATABASE_ROWS sizeof(Database)/sizeof(Database[0])
  </code></pre>
  <p>When #including database.h in application.h (and then application.h in main.cpp) I had issues with Database being multiply defined in main.cpp and application.h so I moved the contents of Database to a new file database.cpp and used the extern declaration which seemed to eliminate the issue of multiple definitions. but now, I get the error</p>
  <blockquote>
  <p>./application.h(24): error: invalid application of 'sizeof' to an incomplete type 'std::int8_t [][16]'</p>
  </blockquote>
  <p>The problem seems to lie with &quot;DATABASE_ROWS&quot; in all my source and header files and I can't quite work out how to get around this.</p>
  <p>So far I have the following files involving the Database array:</p>
  <p><strong>database.h</strong></p>
  <pre><code>#include &lt;cstdint&gt;
  #define DATABASE_COLS 16
  
  extern int8_t Database[][DATABASE_COLS];
  
  // number of rows in the database
  #define DATABASE_ROWS sizeof(Database)/sizeof(Database[0])
  </code></pre>
  <p><strong>database.cpp</strong></p>
  <pre><code>#include &quot;database.h&quot;
  int8_t Database[][DATABASE_COLS] = {
    //20x16 integer values are here, removed on StackOverflow for easier reading
  };
  </code></pre>
  <p><strong>application.h</strong></p>
  <pre><code>#include &lt;cstdint&gt;
  #include &quot;database.h&quot;
  #include &lt;stdint.h&gt;
  using namespace std;
  
  
  class Results {
   public:
      Results() {number = 0;}      // initial location is the start of the 'Data' data store
      void StoreResult(int32_t);   // put an item in the data store
    void EmptyResults();         // reset to point to the start of the data store
   private:
      int32_t Data[DATABASE_ROWS];  // space to store results of processing each row
    uint32_t number;              // current entry being accessed in the 'Data' data store
  };
  </code></pre>
  <p>Could anyone please suggest a way of getting DATABASE_ROWS to work properly without multiple definition? I think I've got a few things mixed up. Thanks!</p>