Re: Not using .cpp files when programming...
- From: alfps@xxxxxxxx (Alf P. Steinbach)
- Date: Wed, 20 Jul 2005 00:55:13 GMT
* 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?
.
- Follow-Ups:
- Re: Not using .cpp files when programming...
- From: Arthur J. O'Dwyer
- Re: Not using .cpp files when programming...
- From: robertwessel2@xxxxxxxxx
- Re: Not using .cpp files when programming...
- From: CBFalconer
- Re: Not using .cpp files when programming...
- References:
- Not using .cpp files when programming...
- From: Eric Fortier
- Re: Not using .cpp files when programming...
- From: robertwessel2@xxxxxxxxx
- Not using .cpp files when programming...
- Prev by Date: Re: Not using .cpp files when programming...
- Next by Date: Naive Bayes Algorithm?
- Previous by thread: Re: Not using .cpp files when programming...
- Next by thread: Re: Not using .cpp files when programming...
- Index(es):
Relevant Pages
|