我有一些代码enum class
。我只希望存在这个枚举类的单个实例。我知道单例类,但是有没有办法让枚举类只在当前文件中可见?
简单的例子:
enum class StateInstanceOption
{
STATE_INSTANCE_A,
STATE_INSTANCE_B
}gCurrentState{StateInstanceOption::STATE_INSTANCE_A}; // global variable to hold current state "pointer" (really a flag)
显然用户需要能够读/写gCurrentState
,但我不希望用户能够创建更多的StateInstanceOption
.
这可能吗?
澄清一下,我不希望用户能够创建另一个实例StateInstanceOption
,但我确实希望他们能够看到gCurrentState
.