M
Mtk
Hi!
Why does the following, simple, example produce such errors?
I know it has to do with the two header files including each other and
(moreover) the usage of the classes One and Two in the "opposite" header
file... What do I have to do to make this example work?
Thanks for all the help!
// * Error messages:
One.h(11): error C2146: syntax error : missing ';' before identifier 't'
One.h(11): error C2501: 'One::Two' : missing storage-class or type
specifiers
One.h(11): error C2501: 'One::t' : missing storage-class or type specifiers
Two.h(11): error C2146: syntax error : missing ';' before identifier 't'
// * File One.h
#ifndef ONE_H
#define ONE_H
#include "Two.h"
class One
{
public:
One();
private:
Two t;
};
#endif
// * File One.cpp
#include "One.h"
One::One()
{
}
// * File Two.h
#ifndef TWO_H
#define TWO_H
#include "One.h"
class Two
{
public:
Two();
private:
One t;
};
#endif
// * File Two.cpp
#include "Two.h"
Two::Two()
{
}
// * File Main.cpp
int main()
{
return 0;
}
Why does the following, simple, example produce such errors?
I know it has to do with the two header files including each other and
(moreover) the usage of the classes One and Two in the "opposite" header
file... What do I have to do to make this example work?
Thanks for all the help!
// * Error messages:
One.h(11): error C2146: syntax error : missing ';' before identifier 't'
One.h(11): error C2501: 'One::Two' : missing storage-class or type
specifiers
One.h(11): error C2501: 'One::t' : missing storage-class or type specifiers
Two.h(11): error C2146: syntax error : missing ';' before identifier 't'
// * File One.h
#ifndef ONE_H
#define ONE_H
#include "Two.h"
class One
{
public:
One();
private:
Two t;
};
#endif
// * File One.cpp
#include "One.h"
One::One()
{
}
// * File Two.h
#ifndef TWO_H
#define TWO_H
#include "One.h"
class Two
{
public:
Two();
private:
One t;
};
#endif
// * File Two.cpp
#include "Two.h"
Two::Two()
{
}
// * File Main.cpp
int main()
{
return 0;
}