是否可以在#define
指令中声明静态变量?
// header file
#define TEXT_ENUM
#ifdef TEXT_ENUM
#define TEXT_HANDLING_MACRO \
static const char * TEXT[]; \
static const char * getText( int _enum ) { \
return TEXT[_enum]; \
}
#else
#define TEXT_HANDLING_MACRO
#endif
struct Foo {
TEXT_HANDLING_MACRO
};
// cpp file
#include "foo.h"
const char * Foo::TEXT[] = {
"ONE",
"TWO",
"THREE",
0
};
当我将此头文件包含在其他文件中并尝试访问Foo::TEXT[]
.