Re: header files

From: mike ttoouli (mttoouli_at_yahoo.com)
Date: 04/05/04


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.
>
>



Relevant Pages

  • Re: forms implementation should be in .cpp not .hpp file
    ... Why VS2008 doesn't create .cpp files when creating new form using ... file not in the header file. ... deliver service pack like compatibility for WindowsForms. ... Stop jumping saying "developers, developers, developers" and ...
    (microsoft.public.vc.ide_general)
  • Preprocessor, nested files etc.
    ... I expected one big file but instead got one preprocessor file for each ... of the cpp files in the project. ... when I #define macros and put them at the beginning of the header file ... then those macro definitions don't seem to stick. ...
    (comp.lang.cpp)
  • Re: header files
    ... >hi jeffc, sorry I wasn't being very clear. ... >It was never my intention to create one big file - lots separate files, ... >then this would ensure that the header file is added only the first time it ... If you cannot see the point of .cpp files I suspect you do not ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Internal Complier Error in VC++ 1.52
    ... You may have hit some brick wall in the compiler. ... I am working on an existing code base where the no of lines is around 100,000, spread across different header and cpp files. ... when i was trying to add a new function declaration for an existing class in a header file and function implementation in the .cpp file i am getting an error as given below ... CL returned error code 2. ...
    (microsoft.public.vc.mfc)
  • Re: code in header file?
    ... Marko Zagar wrote: ... >> is it ok to add code in the header file? ... > Aside from longer compile and link times (if you include that header in ... > other cpp files, the same code will be compiled again), I see no problem. ...
    (alt.comp.lang.learn.c-cpp)