1、概述
C++中出了const关键字以后,宏定义常量的功能已经不在被推荐使用。这使得宏似乎没有了用武之地。实际上,宏还可以做很多事情,笔者也难以全部列举。这里,仅仅列举几个典型的用法,希望大家能够从中获益。
#define?const? or enum?
Tags: C/C++
1.只是声明单一固定值,尽可能采用const。
2.如果是一组固定值,并且互相有关联,则采用enum。
3.不涉及条件编译,只是定义固定值的情形下,尽可能不使用#define。
In this entry, I show you 4 tips that address frequently asked questions from C++ programmers of all levels of expertise. It's surprising to discover how many experienced programmers are still unaware of the deprecation of the .h notation of standard header files, the proper usage of namespaces, and the rules regarding binding of references to temporary objects, for example. These issues and others will be discussed here.