-2

I have a class and it has an integer value that will be used by other classes as well as the original class. And it's a fairly simple value (e.g. the dimensions of a GUI application). In this case, should I define these values as static const int VALUE = 123 or #define VALUE 123 in my header file? Does one have any advantage over the other?

Mertcan Ekiz
  • 691
  • 1
  • 9
  • 22

1 Answers1

2

When you're using C++ you almost never need to use #define. (Only with include guards)

#define knows nothing about semantics of code. It simply replaces text VALUE with defined value.

static const int is much better choice then. It is recommended way to use constants.

justanothercoder
  • 1,830
  • 1
  • 16
  • 27