Header or new cpp file?

Started by
1 comment, last by Sirveaux 20 years, 9 months ago
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).
Advertisement
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.
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]

This topic is closed to new replies.

Advertisement