자기개발/C++ #ifndef vs #pragma once 2021. 7. 2. 중복 컴파일 방지를 위해 자주 쓰이는 전처리기 지시자들에 대해 비교해 보고자 한다. 1) #ifndef 먼저 다음과 같은 코드가 있다고 하자. First.h 1 2 3 4 5 6 7 #ifndef _FIRST #define _FIRST class First { }; #endif Second.h 1 2 3 4 5 6 7 8 9 #ifndef _SECOND #define _SECOND #include "First.h" class Second { }; #endif Main.cpp 1 2 3 4 5 6 #include "First.h" #include "Second.h" void Main() { } Main.cpp 를 컴파일 해보면 #include 의 작동방식에 따라 그 파일의 코드가 그대로 복사될 것이다. 1.. 이전 1 다음