Archived

This topic is now archived and is closed to further replies.

Sirveaux

Header or new cpp file?

Recommended Posts

I''m fairly new to C programming so all of my programs have been single-source programs. My latest projects have made me need more portable code and I''m not sure when it''s a good idea to make an new cpp file or make a header? What determines which you should use? Right now, I have the main group of classes that will be used by my entire program as well as another program in a single header file. What about a collection of related fuctions? Would they go in a header file of their own or into another cpp file and just ''extern''ed into whatever file I plan to use them in? I''m just not sure what the common conventions are for C++. (All of my previous programming experience has been in one form of BASIC or another).

Share this post


Link to post
Share on other sites
A good technique would be to create a new header and source file for each class or group of classes that logically go together. When you include the header in any source file, you will be giving that source the prototype of only the class that it needs. I usually have nearly the same number of source files as I do header files.

Share this post


Link to post
Share on other sites
Sorry if this sounds arrogant, but you might want to check out my ''Organizing Code Files'' article (which should be in my signature below). It got some good praise at the time so maybe it''ll help you too.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites