Last active
June 9, 2016 07:11
-
-
Save tenpoku1000/3d7d389c297c723caaf7 to your computer and use it in GitHub Desktop.
C++ でグローバル定数を宣言する場合のイディオム。定数の唯一の定義をマクロ HEADER_H_ で指示することで実現する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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