Subj : Re: Not using .cpp files when programming... To : comp.programming From : robertwessel2@yahoo.com Date : Tue Jul 19 2005 02:03 pm Eric Fortier wrote: > Hi all, > > 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. You'll have routines multiply defined when you include the same .h in multiple programs that are linked together. Or, if you make the member functions static or inline in the class to avoid the name space problems, you'll make a larger executable because all the code is duplicated in each compiled program, perhaps many times. In the later case you may also have difficulty with any globals you may need. If the class is small, and essentially all the member functions are intended to be inlined anyway, there's not much harm in having everything in the .h. .