一下列子重载了 bool 以及逗号, ==, <<等运算操作符!
template<typename T>
class Optional{
public:
Optional() : present(false)
{
}
~Optional()
{
}
operator bool() const
{
return (present ? false : true);
}
bool operator==(const Optional &rhs)
{
return (present = rhs.present);
}
bool operator != (const Optional &rhs)
{
return !this->operator==(rhs);
}
Optional& operator , (T tOBJ)
{
return *this;
}
friend ostream& operator<<(ostream& out, const Optional<T>& t)
{
return out << "data is " << t.get() ;
}
private:
bool present;
};