const extern C-array linker multiple definitions
<p>I've got several source files for updating them. They refuse to compile for quite obvious reason (all uninteresting source stripped):</p>

<pre><code>// hashset.h
class HashSet {
    unsigned prime = 0; // Index to table size (c++11 syntax)
    unsigned long table_size () const { return prime_list [prime]; }
};

//hashet.cpp
const unsigned long prime_list [] = {53, 97, 193, 389, 769,
      1543, 3079, 6151, 12289, 24593, 49157, 98317};
</code></pre>

<p><code>prime_list</code> is undefined when called from <code>HashSet::table_size</code> in the header. I tried to fix the source, adding <code>extern const unsigned long prime_list [];</code> to the header and <code>extern</code> to this array definition. After <code>make clean &amp;&amp; make</code> I got </p>

<pre><code>g++ main.o dictionary.o hashset.o  -o spell
dictionary.o:(.rodata+0x4): multiple definition of `num_primes'
main.o:(.rodata+0x4): first defined here
dictionary.o:(.rodata+0x20): multiple definition of `prime_list'
main.o:(.rodata+0x20): first defined here
hashset.o:(.rodata+0x4): multiple definition of `num_primes'
main.o:(.rodata+0x4): first defined here
hashset.o:(.rodata+0x20): multiple definition of `prime_list'
main.o:(.rodata+0x20): first defined here
collect2: error: ld returned 1 exit status
</code></pre>

<p>As I found out, in fact if just <code>prime_table</code> is defined as</p>

<pre><code>// hashset.cpp
extern const unsigned long prime_list [] = {53, 97, 193, 389, 769,
      1543, 3079, 6151, 12289, 24593, 49157, 98317};
</code></pre>

<p>and the body of <code>table_size ()</code> is moved to <code>hashset.cpp</code> (to avoid compilation errors), I get these linker errors. Without <code>extern</code> I have no errors. Why is it so? I have only one definition of this array, I do not expose it in any manner to other my source files (I do not put <code>extern const unsigned long prime_list [];</code> to the header now). How it can be multiply defined?</p>

<p>To be clear, my source now:</p>

<pre><code>// hashset.h
class HashSet {
    unsigned prime = 0; // Index to table size (c++11 syntax)
    unsigned long table_size () const;
};

//hashet.cpp
extern const unsigned long prime_list [] = {53, 97, 193, 389, 769,
      1543, 3079, 6151, 12289, 24593, 49157, 98317};
unsigned long HashSet::table_size () const {
     return prime_list [prime];
}
</code></pre>

<p>Now <code>extern</code> in the <code>.cpp</code> is unnecessary, but I just wonder, what's wrong? And is there a way to put back the body of <code>table_size()</code> to the header file to allow it to be inline?</p>

<p><strong>upd</strong> <code>prime_list</code> and <code>prime_table</code> are the same object. I mistakenly changed the name while shortening the source for this post; fixed now.</p>
