Hi,
I have 2 classes, h1 and h2, declared in 2 seperated header files h1.h
and h2.h and implementated in 2 seperated source files h1.c and h2.c.
The h1.h looks like this,
#ifndef H1_H
#define H1_H
#ifndef H2_H
#include "h2.h"
#endif
namespace ns {
class h1 {
<some stuff>
}
}
#endif
The h2.h looks like this,
#ifndef H2_H
#define H2_H
#include "h1.h"
// NOTICE that I include the header without condition
namespace ns {
class h2 {
h1 h1_obj;
<some stuff>
}
}
#endif
the h1.c looks like this,
#ifndef H1_H
#include "h1.h"
#endif
<some code>
when I compile h1.c using Visual C++ compiler I get an error, error
C2079: 'h1_obj' uses undefined class 'ns::h1'.
Then I updated h2.h by adding a forward declaration of class h1 like
this,
#ifndef H2_H
#define H2_H
#include "h1.h"
namespace ns {
class h1;
class h2 {
h1 h1_obj;
<some stuff>
}
}
#endif
But I get the same error.
Any idea?