Declaring statics in a header file?
O_o
Right to point out the issue; wrong way to point the issue out.
1): A `static' variable is different than a `static' member variable.
2): Definitions are not declarations.
Code:
class S{static int m;}; // a non-template declaration of a `static' member variable which is really a global with specific visibility
Code:
int S::m; // a non-template definition of a `static' member variable which must appear exactly once in a given, linked, binary
[Edit]
To clarity, a global variable marked `static' is different in that such a variable is considered to have "internal linkage" which is a fancy way of saying that even though each translation unit including the definition of the variable gets a copy of that variable something is done to the label/memory so that multiple definitions are not a problem.
[/Edit]
Well, the library itself is contained within a single header file, so...where else to put them?
Well, the correct answer is "Any specific translation unit you wish to provide.".
Despite what you imagine, considering the emoticon, the definition appearing in a header is a mistake.
The definition appearing in a header results in a definition appearing in every translation unit where the header is included which results in, usually, linker errors.
[Edit]
You can use templates to solve the issue without distributing a source file or using macro trickery--one possible C solution.
You just need to separate the `static' member variable bits into a template component which forces the compiler suite--generally linker--to perform the same sort duplicate elimination required by general template expansion.
Code:
template <typename IGNORED> class S_t{protected:static int m;}; // declare `static' member variables
template <typename IGNORED> int S_t<IGNORED>::m = 0; // define `static' member variables
class S: public S_t<void>
{
/* the magic line `public', `private', or `protected' */ public: using S_t<void>::m;
};
[/Edit]
Soma