Separate code into multiple files

Good day.
I have a question about separating code and using header files.
My goal is…

  1. Having a layout where most include files are specified only in one place
    2.Having my functions and structs in individual files
  2. Be able to write functions and structs in any order. For example. as you will see later in my sample code below:
    test1() calls test2(), which is defined after test1(). No problem here because they have been declared in header.h.

I read that you usually only have one header file and the rest cpp. But the layout I now have (sample code below) have worked well and fulfills the above(1, 2 & 3) except that in structs.h I would have liked to have a namespace at the top of structs.h that looks like this:
namespace S {map <int, a> my map;}
Which won’t work because “struct a” comes after the namespace


#include header.h
#include header.h

int main() {

Here I have function calls and some variables
(E.g. myfunction(); var a = 2;)


Here I have all the include files used by the other files (project.cpp, structs.h, functions.h). (so I don’t need to specify the same include files in several places)

void test1();
void test2();
#include <iostream>
#include <map>
#include "structs.h"
#include "functions.h" 

Here I have all my structs.

struct a {

int a = 2;
int b;

a() {
int b = 4;


struct b {

int z = 22;


Here I have all my functions.

void test1() {



void test2() {

cout << "yo"