아래 예제가 왜 에러가 나는지 이해하자.
어떻게 해결해야 할지 생각해보자.
#include "horse.h"
#include "donkey.h"
int main() {
neigh();
hee_haw();
return (0);
}
#ifndef __DONKEY_H__ // (1) 헤더 가드 적용
#define __DONKEY_H__
#include "horse.h"
void hee_haw() { // 당나귀, 히호
neigh();
}
#endif
horse.h를 코딩하다가, hee_haw() 함수를 호출하고 싶어서, 아래와 같이 코딩했다고 가정하자.
#ifndef __HORSE_H__
#define __HORSE_H__
#include "donkey.h"
void neigh() { // 말, 히힝
hee_haw();
}
#endif
이런 경우 neigh함수가 없다고 에러가 난다.