Why is #define bad and what is the proper substitute?

后端 未结 6 1144
情深已故
情深已故 2020-11-30 12:37
#define dItemName        L\"CellPhone\"
6条回答
  •  日久生厌
    2020-11-30 13:11

    One major problem with #define is that it is outside of the language itself and therefore is not limited to a given scope. You will replace dItemName anywhere in the translation unit, in all namespaces, classes, functions, etc.

    I'd replace it with const std::wstring dItemName = L"CellPhone";

提交回复
热议问题