GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Mar-2004, 03:17
BlueTeeth's Avatar
BlueTeeth BlueTeeth is offline
New Member
 
Join Date: Mar 2004
Posts: 9
BlueTeeth is on a distinguished road
Question

Cross include


hi all,i have some problem and i`m not sure about the source
i have 2 classes
CPP / C++ / C Code:
#include "slot.h"
class cell
{
private:
	char content;
	bool occupied;
	bool SlotBegin;      // TRUE if this cell is the begining of slot
	slot* BlngTo;        // Points to slot it belongs to  
CPP / C++ / C Code:
#include <string>
#include "cell.h"
using std::string ;

class slot
{
private:
	int row,col,size;
	char dir;
	string content;
	bool occupied;
	vector<cell*> contain;  // POINTERS to cells it contains
these were part of the interface of the 2 classes and it gives me errors at compiling is it because i can`t include cell.h in slot.h and in the same time include slot.h in cell.h ? if so what`s the solution?!
thnx in advance
  #2  
Old 24-Mar-2004, 08:22
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi BlueTeeth.

I found a little trick that is implemented in all of the standard libraries. You need to include these files, but you don't want to include them if they are already included.

So at the very top of includes, I always put:
CPP / C++ / C Code:
#ifndef __HEADER_NAME
#define __HEADER_NAME

And at the end put:
CPP / C++ / C Code:
#endif //__HEADER_NAME

Your __HEADER_NAME is a unique name based on your file, I ussually use things like __CROSS_H.

This way, the include file will be gone through only once, even if it is included by several files.

HTH
d
  #3  
Old 24-Mar-2004, 21:29
BlueTeeth's Avatar
BlueTeeth BlueTeeth is offline
New Member
 
Join Date: Mar 2004
Posts: 9
BlueTeeth is on a distinguished road
Quote:
Originally Posted by dsmith
Hi BlueTeeth.

I found a little trick that is implemented in all of the standard libraries. You need to include these files, but you don't want to include them if they are already included.

So at the very top of includes, I always put:
CPP / C++ / C Code:
#ifndef __HEADER_NAME
#define __HEADER_NAME

And at the end put:
CPP / C++ / C Code:
#endif //__HEADER_NAME

Your __HEADER_NAME is a unique name based on your file, I ussually use things like __CROSS_H.

This way, the include file will be gone through only once, even if it is included by several files.

HTH
d
i did that in the top of my files but i didn`t copy it but my problem is that in the "cell.h" i want to include "slot.h" and in the same time in the "slot.h" i need to include "cell.h" ?!
i mean for example when compiling cell.cpp the compiler will need "slot.h" while the slot.h contains some "cell" members!!what`s the solution
  #4  
Old 24-Mar-2004, 21:37
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by BlueTeeth
i did that in the top of my files but i didn`t copy it
meaning what exactly?

Quote:
Originally Posted by BlueTeeth
but my problem is that in the "cell.h" i want to include "slot.h" and in the same time in the "slot.h" i need to include "cell.h" ?!
The solution is exacty what dsmith described to you.

Quote:
Originally Posted by BlueTeeth
i mean for example when compiling cell.cpp the compiler will need "slot.h" while the slot.h contains some "cell" members!!what`s the solution
slot.h has part of the cell class inside it? If so, rethink your code.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 16:41
Including Maps and strings?? maddie C++ Forum 17 05-Jul-2004 07:25
some I/O problems...again cameron C++ Forum 3 03-Mar-2004 22:39
Need help adding a footer demtro MySQL / PHP Forum 2 10-Feb-2004 20:48
Cross Site Scripting Vulnerabilities - XSS JdS Web Design Forum 0 27-Nov-2002 07:08

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:00.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.