LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2006, 02:42 AM   #1
EAD
Member
 
Registered: Mar 2006
Distribution: ARCH linux
Posts: 137

Rep: Reputation: 15
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?
 
Old 04-19-2006, 04:21 AM   #2
Ellops
Member
 
Registered: Nov 2005
Location: ath.gr
Distribution: Slackware 11.0 / 2.6.19.1 /Linux Mint
Posts: 124

Rep: Reputation: 15
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

Last edited by Ellops; 04-19-2006 at 04:34 AM.
 
Old 04-19-2006, 07:38 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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"
 
Old 04-20-2006, 06:37 AM   #4
EAD
Member
 
Registered: Mar 2006
Distribution: ARCH linux
Posts: 137

Original Poster
Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
include/linux/types.h and include/linux/posix_types.h kpachopoulos Programming 2 11-26-2005 05:52 AM
Help for C++ include harrylee2003 Programming 3 09-28-2005 05:01 PM
include question jnusa Programming 3 09-06-2004 12:31 PM
Path to include? Mazen Alzogbi Red Hat 1 11-15-2003 06:25 AM
Include dir help gilinko Slackware 1 07-06-2002 07:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration