static const vs #define

前端 未结 11 995
醉话见心
醉话见心 2020-11-22 13:01

Is it better to use static const vars than #define preprocessor? Or maybe it depends on the context?

What are advantages/disadvantages for

11条回答
  •  暖寄归人
    2020-11-22 13:16

    Defining constants by using preprocessor directive #define is not recommended to apply not only in C++, but also in C. These constants will not have the type. Even in C was proposed to use const for constants.

提交回复
热议问题