Skip to main content
1 of 3
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Header file:

  • It's usually preferred to have your own headers before library headers. This can help avoid possible dependencies and also keep the headers more organized.

  • Do not use using namespace std in a header file. It can be okay to have it in an implementation file due to the locality (.cpp files do not get imported), but having it in a header file will force users to have the std namespace exposed, which can possibly break their code. Just leave it out and use std:: where appropriate.

  • Macro constants (or macros in general) are not very common in C++, and are primarily discouraged as there are better ways of doing things. Specifically, the const keyword should be used to make something constant and prevent any further changes to it.

      const int WORLD_HEIGHT = 4;
    

    Moreover, as these are in a header file, they will be global by default. While it is not such a bad thing since they cannot be modified, it would be safer to have them contained within a namespace or a class (only if it belongs in a class).

      namespace vals
      {
          const int WORLD_HEIGHT = 4;
          // ...
      }
    

    The constant can then be accessed via the scope operator (::):

      int height = vals::WORLD_HEIGHT;
    

    Note: The name vals is only an example, so feel free to give a more relevant name. As a user may be using it frequently (unless using is used), try to make it short.

  • It's a little confusing to have multiple public and private sections. Just group them into one.

    Also, centerLoaded should be private as it is a data member. That should not be exposed to the public interface.

Jamal
  • 34.9k
  • 13
  • 133
  • 237