0

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

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Narue
0

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();
}

0

>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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.