Why use #define instead of a variable

后端 未结 8 1421
清酒与你
清酒与你 2020-12-04 06:19

What is the point of #define in C++? I\'ve only seen examples where it\'s used in place of a \"magic number\" but I don\'t see the point in just giving that val

8条回答
  •  春和景丽
    2020-12-04 06:29

    #define can accomplish some jobs that normal C++ cannot, like guarding headers and other tasks. However, it definitely should not be used as a magic number- a static const should be used instead.

提交回复
热议问题