LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c/c++ include conflict (https://www.linuxquestions.org/questions/programming-9/c-c-include-conflict-436654/)

EAD 04-19-2006 02:42 AM

c/c++ include conflict
 
Hii, I have two .h files one name x and one name y
I want to do in x
#include "y.h"

and in y I need to define an x type so I need
#include "x.h"
but then when compiling my make file I get an error ISO C++ forbids declaration of 'X' with no type
what can I do please?

Ellops 04-19-2006 04:21 AM

in x u include types from y and in y from x...

That's a problem... try to separete the things u declare in x which included in y in a different header z (or those of y in x) and include z instead..

or in a way that x won;t need y to define itsown types and vice versa

graemef 04-19-2006 07:38 AM

You can also add a forward declaration.

in X you might have:

class Y;
class X{... private: Y * myY, ...};
#include "y.h"

and in Y you might have:

class X;
class Y{... private: X * myX, ...};
#include "x.h"

EAD 04-20-2006 06:37 AM

Quote:

Originally Posted by graemef
You can also add a forward declaration.

in X you might have:

class Y;
class X{... private: Y * myY, ...};
#include "y.h"

and in Y you might have:

class X;
class Y{... private: X * myX, ...};
#include "x.h"

Tanx ;) that is waht I was looking too


All times are GMT -5. The time now is 04:03 PM.