Skip to content

Instantly share code, notes, and snippets.

@tenpoku1000
Last active June 9, 2016 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenpoku1000/3d7d389c297c723caaf7 to your computer and use it in GitHub Desktop.
Save tenpoku1000/3d7d389c297c723caaf7 to your computer and use it in GitHub Desktop.
C++ でグローバル定数を宣言する場合のイディオム。定数の唯一の定義をマクロ HEADER_H_ で指示することで実現する
(1) Header.h
#if defined(HEADER_H_)
extern const int global = 100;
#else
extern const int global;
#endif
(2) consumer.cpp
#include "Header.h"
(3) main.cpp
#define HEADER_H_
#include "Header.h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment