I had a problem writing C ++ code that needs to be compiled in Visual Studio 2008 and in GCC 4.6 (and also need to be compiled back in GCC 3.4): static const int members of the class.
Other questions have covered the rules needed for static members of the const int class. In particular, the standard and GCC require that a variable has a definition in one and only one object file.
However, Visual Studio generates an LNK2005 error when compiling code (in debug mode) that includes a definition in a .cpp file.
Some of the methods I'm trying to solve are as follows:
- Initialize it with the value in the .cpp file, not the header.
- Use the preprocessor to remove the definition for MSVC.
- Replace it with a listing.
- Replace it with a macro.
The last two options are not attractive, and I probably will not use them. The first option is simple - but I like to make a difference in the title.
What I'm looking for in the answers is a good, effective code structuring method that makes GCC and MSVC both happy. I hope for something wonderfully beautiful that I have not thought of yet.
source share