This is a very general question. I'm sure there is no "right" way so I thought I'd ask for opinions/common practice.

In my file MainProgram.cpp (containing main()), sometimes I will have LOTS of functions. It seems very distracting to have a thousand lines of code all in the same file, I'll have to page down many many times to find what I am looking for. Is there a good way to kind of group functions together into separate files that make them easier to locate and less "in the way"?

Thanks!

David

You can have namespaces and include some of your functions in a separate namespace. Then use the namespace i guess.

If you can make function.h containing the namespace "namespace1" then i think... (This will be the code for that )

#include <function.h>
using namespace namespace1;

int main(){
function 1();
}

>It seems very distracting to have a thousand lines of code all in the same file
Modern IDEs make it very simple to deal with this, provided the thousand lines are all relevant to the file.

>Is there a good way to kind of group functions together into separate
>files that make them easier to locate and less "in the way"?
Yes, design your code such that each file represents a module, where each module contains the functions and classes necessary to perform related tasks. Repeat and recurse as necessary and you'll have a nice module hierarchy. Namespaces go a long way toward making this structure comprehensible in the client code.

This article has been dead for over six months. Start a new discussion instead.