问题
假设我有这样的课程:
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";
换句话说,我应该如何以及在哪里捕获输出状态?