Why not to use macros (#define) in modern C++

What are disadvantages of using macros?

— > You cannot debug macros.

What should be the replacement for macros?

Macros are replaceable with enum class, const, inline, typedef, template and constexpr.

Noncompliant Code Example

#define MAX_MEMORY 640 // Noncompliant#define LEFT   0 // Noncompliant
#define RIGHT 1 // Noncompliant
#define JUMP 2 // Noncompliant
#define SHOOT 3 // Noncompliant

Compliant Solution

constexpr size_t MAX_MEMORY = 640;
enum class Actions {Left, Right, Jump, Shoot};

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store