假设我有一个类T,其中:
我对像枚举一样的类感兴趣,例如:
- T没有虚函数。
- T实例没有状态。
- T有自身的静态成员实例。
- T本身没有其他状态。
我对像枚举一样的类感兴趣,例如:
// Switch.h
class Switch {
public:
static Switch const ON;
static Switch const OFF;
bool operator== (Switch const &s) const;
bool operator!= (Switch const &s) const;
private:
Switch () {}
Switch (Switch const &); // no implementation
Switch & operator= (Switch const &); // no implementation
};
// Switch.cpp
Switch const Switch::ON;
Switch const Switch::OFF;
bool Switch::operator== (Switch const &s) const {
return this == &s;
}
bool Switch::operator!= (Switch const &s) const {
return this != &s;
}