: 헤더 가드에서 http://www.learncpp.com/cpp-tutorial/110-a-first-look-at-the-preprocessor/C++ -이 헤더가 두 번 나타나지 않게하려면 어떻게해야합니까? 에서
, 그 코드 조각이 있습니다
add.h :
#include "mymath.h"
int add(int x, int y);
subtract.h :
#include "mymath.h"
int subtract(int x, int y);
MAIN.CPP :
#include "add.h"
#include "subtract.h"
main.cpp
에 #include "mymath.h"
이 두 번 나타나지 않게하려면 어떻게해야합니까?
감사합니다.
왜 두 번 포함시키지 않으시겠습니까? – sth
include guard의 요점은 전처리 기가 동일한'#include '를 두 번 이상 보지 못하게하는 것이 아니라 mymath.h의 실제 코드가 두 번 포함되지 않도록하는 것입니다. mymath.h에 가드가 포함되었다고 가정하면 괜찮습니다. –
답변은 실제로 해당 자습서의 다음 단락에 있습니다. 왜 그 질문을 여기에 묻는거야? –