Search code examples
c++structurefile-structure

File structure of a Procedural C++ program


I am new to c++ and am writing a procedural program to get the hang of that side of it. I will have a collections of functions that call each other and some include statements, namespace statements, and constant declarations.

My questions are:

What are some guidelines for the file structure of the program ? Should I break this apart with some functions in another file(s) if so are their some standards for what categories of functions deserve their own file?

I hope this question is specific enough. I am NOT looking for the "best" way to do this, just some general guidelines people use.

Thanks so much.


Solution

  • Basically, you should group your procedures in some kind of logic and put them together in one file. Then it's a lot easier to read code and it's much more elegant than having only a few extensive files. A good practice is also to make declarations of functions at the top of the file and their definitions at the bottom.

    //declarations
    void myfun(int a);
    /...
    
    //definitions
    void myfun(int a)
    {
    //do sth
    }