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

后端 未结 6 1233
日久生厌
日久生厌 2020-12-15 07:35

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

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 08:07

    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.

提交回复
热议问题