Re: Not using .cpp files when programming...



* robertwessel2@xxxxxxxxx:
> * Eric Fortier:
> >
> > When I'm writing a C++ class, I've built up this habit of putting all my code
> > right in the .H header file with the class definition. I'm not doing that with
> > 100% of my code, of course, only when I make a utility class (CRC, string,
> > loader, etc).
> >
> > I know this can't be good practice, but as of yet I never had any problems. I
> > find it a lot easier to maintain too, and I don't have to keep adding .CPP to
> > the projects I work on; I just add the header and I'm done.
> >
> > In the interest of searching for non-existent problems, can anyone tell me what
> > is wrong with this? ;)
>
> Your compiles will be slower.

Generally correct.


> You'll have routines multiply defined
> when you include the same .h in multiple programs that are linked together.

Sorry, that's incorrect: it's not programs that are linked together, it's
compilation units.


> Or, if you make the member
> functions static or inline in the class to avoid the name space problems,

Sorry, that's incorrect: neither 'inline' nor 'static' is used to avoid name
space problems.


> you'll make a larger executable because all the code is duplicated in each
> compiled program, perhaps many times.

Sorry, that's incorrect: the main feature of 'inline' is the acceptance &
removal of multiple definitions.


> In the later case you may also have difficulty with any
> globals you may need.

There are techniques to deal with that. Template programming still requires
doing mostly everything in header files (in practice; in theory there is
'export' which 1 compiler implements). The language has special support for
defining, not just declaring, globals in headers, although there are also
features that make globals technically unnecessary.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.



Relevant Pages

  • Re: static : ignored on left of const double when no variable is declared
    ... I have the following lines in my header file I know I could use ... compiles OK, and in this case it does for me, look for differences between ... all-caps for a variable name, and all-caps at least informally is usually ... I'd suspect a conflicting macro definition. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Linmking problem
    ... > I have a got a library (actually the whole dang project) that compiles fine ... i have added the header file in my new project and have added the ... i am attaching the header and lib ...
    (microsoft.public.vc.language)
  • Re: IntelliSense is locking VS C++.NET Express
    ... The header file contained the definition of ... > and start adding existing source files. ... > adding 6 files, "Updating Intellisense" appears, and VS hangs. ... Compiles well, Intellisense updates ok. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Javas performance far better that optimized C++
    ... > If you want you can place the class definition in the header file, ... > collector destroys the object (for managed objects). ... It is not the same as destructor, it is used to call destructors ...
    (comp.lang.cpp)
  • Re: IntelliSense is locking VS C++.NET Express
    ... >contents of the header file, deleting the header file, creating a new ... and start adding existing source files. ... After adding 6 files, "Updating Intellisense" appears, and VS ... Compiles well, Intellisense updates ok. ...
    (microsoft.public.dotnet.languages.vc)