#define statements within a namespace

前端 未结 5 1559
旧巷少年郎
旧巷少年郎 2021-02-01 12:34

If I have a #define statement within a namespace as such:

namespace MyNamespace
{
  #define SOME_VALUE 0xDEADBABE
}

Am I correct in saying that

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 12:57

    Yes. In general, using const values instead of #define'd values has many advantages. Restricting the scope of the variable is one of the advantages. The scope can be restricted to a namespace, or to any another valid scope this way (including at the class level, function level, etc).

提交回复
热议问题