问题
假设我有这样一个类:
enum eOutputMode
{
DECIMAL,
BILLS_AND_COINS
};
class BankAccount
{
ssize_t m_dollars;
unsigned short m_pennies;
public:
friend ostream& operator<<( ostream& os, BankAccount const& rhs )
{
// switch on eOutputMode : output in DECIMAL or in BILLS_AND_COINS
return os;
}
};
问题
如何修改上面的代码,以便我可以像这样调用它?
BankAccount ba;
os << eOutputMode::DECIMAL << ba << "\n";
os << eOutputMode::BILLS_AND_COINS << ba << "\n";
换句话说,我应该如何以及在何处捕获输出状态?