c++global-variables

Where should you put global constants in a C++ program?


Where would you put global constants in a C++ application? For example would you put them in a class? In a struct?


Solution

  • I would use a namespace for global constants which are not very strongly associated with a single class. In the latter case, I would put them in that class.

    Really global (application-level) constants should be in the application's namespace (provided your application is inside it's own namespace, as it should be). For module-level constants, the module's own namespace is the natural place.