Re: header files
From: mike ttoouli (mttoouli_at_yahoo.com)
Date: 04/05/04
- Next message: sasha: "Re: Where to start? - At the beginning"
- Previous message: Paul: "Re: 2D array of pointers"
- In reply to: jeffc: "Re: header files"
- Next in thread: Francis Glassborow: "Re: header files"
- Reply: Francis Glassborow: "Re: header files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 5 Apr 2004 19:53:23 +0100
hi jeffc, sorry I wasn't being very clear.
It was never my intention to create one big file - lots separate files, each
being used by one another. All the code could just be written in .h files,
and used by other .h files by including them (#include "filename.h" - can
this be done with cpp files?).
This would lead to the problem of including the same header file in more
than one place in a large program, but by enclosing the code in each header
file using:
#ifndef FILENAME_H
#define FILENAME_H
..code...
#endif
then this would ensure that the header file is added only the first time it
is encountered in a program, as after that FILENAME_H is defined.
well i think that makes sense. I've implemented a fairly large program only
using header files, and I couldn't really see the point of .cpp files at
all.
cheers
mike
"jeffc" <nobody@nowhere.com> wrote in message
news:40717055_2@news1.prserv.net...
>
> "mike ttoouli" <mttoouli@yahoo.com> wrote in message
> news:71484f98.0404041249.31f7d076@posting.google.com...
> > Hi
> >
> > I'm a little confused about the reason for using both header and cpp
> > files in a project. As all code can be written in the header file
> > itself, why use cpp files at all?
>
> Don't you mean that all the code can be written in the cpp files, so why
use
> a header file?
>
> > I can see there being a redeclaration issue if a header file is
> > included multiple times in a large project, but can't this be
> > by-passed with #ifndef /#define /#endif ?
> >
> > I know this is probably very bad form - can anyone tell me the reasons
> > for the .h / .cpp system?
>
> Again, you've got it backward. You say you can fix the "multiple include"
> problem with the "ifndef..." idiom. Well, what are those files supposed
to
> be included in? The point is, you can do everything you want in one big
> file. When it gets too big to share or organize properly, then you split
it
> into separate files.
>
>
- Next message: sasha: "Re: Where to start? - At the beginning"
- Previous message: Paul: "Re: 2D array of pointers"
- In reply to: jeffc: "Re: header files"
- Next in thread: Francis Glassborow: "Re: header files"
- Reply: Francis Glassborow: "Re: header files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|