【发布时间】:2017-10-10 08:18:18
【问题描述】:
我有一个库(MyLib.h 和 MyLib.cpp),它为某些类(即ClassX、ClassY 等)提供例程。
在MyLib.h 中,我使用#define 预处理器指令定义了两个常量:
#define LOCAL_STR "this string can not be shared among classes that don't #include "MyLib.h""
#define TOSHARE_STR "this string can be shared among classes that #include "MyLib.h""
两个字符串值都建议我想在哪里使用每个字符串。在我看来,第一个只能在MyLib.cpp代码中使用,而第二个必须在ClassX、ClassY等代码中使用。
C++ 是否提供了一种方法来定义这两个常量所需的可见性?目前它们随处可见......
【问题讨论】:
-
类不#include 东西,翻译单元做。 #defines 不是常量,它们是文本替换规则
标签: c++ access-modifiers