Leaving aside the merits of this technique, the code in your question works because of the include guard:
#ifndef MYMAP
#define MYMAP
...
#endif
The second time the .h
is included, it is effectively a no-op since MYMAP
has been defined the first time round.
P.S. Don't do using namespace std
in a header file. Any code that includes this header will have the entire std
namespace brought into the current scope irrespective of whether they want it or not.