Show differencesHistory of post edits
Posted 23 November 2012 - 04:12 AM
First of all, in your Constants.cpp file you need to write "const int MAX_INTS = 1000; "
The extern keyword means "declare without defining". In other words, it is a way to explicitly declare a variable, or to force a declaration without a definition.
The practice itself (putting the initialization into the cpp file) is a matter of personal taste. I personally like it because if i need to change the value for whatever reason, not every single file which includes the header file is compiled again.
But i wouldnt use "extern" anymore....i like static const uint32 MAX_INTS; in a header file more. ;-)
I think this is wrong. When you use the 'const' keyword, the 'static' keyword is implicitly included, so doing "extern const int iMyConst" in the .cpp file is the only way you can then use "extern const int iMyConst;" in the .h file. In this scenario, the 'extern' in the .cpp file is just cancelling out the implicit 'static' and is necessary to allow you to access constants from other .cpp files using extern.