From: kagenin AT usa DOT net (Kagenin) Newsgroups: comp.os.msdos.djgpp Subject: Re: design question Date: Thu, 01 Apr 1999 06:36:35 GMT Message-ID: <37031294.14815147@news.jps.net> References: X-Newsreader: Forte Free Agent 1.11/32.235 NNTP-Posting-Host: 209.142.59.220 X-Original-NNTP-Posting-Host: 209.142.59.220 X-Trace: 1 Apr 1999 07:00:07 -0800, 209.142.59.220 Lines: 39 X-Original-NNTP-Posting-Host: 209.63.224.240 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Matthew Heyman was feeling all groovy on Wed, 31 Mar 1999 22:34:11 +0000 when they posted : >Hello > I was recently messing with a program I was writing, and was wondering >if there was any worth in breaking it up into smaller .cpp files with >very specific stuff, IE one for keyboard commands, one for various other >stuff. Is it wise to do this, or is it just a preferential thing? I >was also wondering how to actually implement functions from other .cpp >files into the main file. I tried a direct cut-paste into a second >file, but ended up with a bunch of errors. I'm not sure how to do it in >the first place, and that could be my problem. Any thoughts, pointers, >or ideas? > >Matthew Heyman The more modular your project is, the better. Try this. Put related functions, or a full class interface, or all your structs and enums and stuff into their own header file. Call it myfile.h. (don't forget the multiple inclusion guards!) Give a definition for all the stuff in myfile.h in a file called myfile.cpp. Have myfile.cpp #include "myfile.h". Compile this with -c (compile only, don't link). In a file that has to use these functions, #include the header file, and on the command line, throw in myfile.o somewhere. This is called modular compilation. It's how you use functions in other source files. This, of course is an overly simplistic model, but it works. Kagenin --- "When the Going gets Weird, the Weird turn Pro" -Hunter S. Thompson