我有以下课程:
class washm_t
{
public:
enum door_t { closed = 0, open = 1 };
private:
door_t door_state ;
public:
int open() ;
};
类的问题在于,open
名称既被定义为类内部方法的名称,又被定义为枚举类型的值。
问题是:我可以以某种方式修改代码,以便两个名称都可以在类内部工作,还是应该为方法或枚举类型值open
选择其他名称?open()
open
这是open()
函数的样子:
int washm_t::open()
{
if(door_state == open) // ~fails, 'open' interpreted as name of method
// not as name of enum type value
return 1 ;
else
return door_state = open, 0 ;
}