부모가 자식의 헤더를 포함하고, 자식이 부모의 헤더를 포함시키도록 구성했을때, 중첩 클래스(순환 참조)가 되버리는 바람에 다음과 같은 에러가 발생한다.

fatal error C1014: 포함 파일이 너무 많습니다 : 수준 = 1024 /* error */
error C2143: 구문 오류 : ';'이(가) '*' 앞에 없습니다. /* error */
error C4430: 형식 지정자가 없습니다. int로 가정합니다.

에러가 발생하는 헤더 중첩, 순환 참조 클래스
#include "Child.h"
class CParent
{
    CChild* m_pChild;
};

#include "Parent.h"
class CChild
{
    CParent* m_pParent;
};
 
이런 경우 #ifndef #define #endfi 나 #pragma once같은 방법을 사용해도 처리가 안되는데, 다음과 같이 수정하면 된다.
#include "Child.h"
class CParent
{
    CChild* m_pChild;
};

class CParent; // #include 대신 class로 선언해줌.
class CChild
{
    CParent* m_pParent;
};
Posted by 극악해골