inherit the ostream

class cdebug_stream :public ostream
{
public:
	typedef cdebug_stream& (*manip_fnptr)(cdebug_stream&);
	void attach(ostream& os) { m_outs.push_back(&os); }
	void detach(ostream& os) { m_outs.erase(std::remove(m_outs.begin(),m_outs.end(),&os),m_outs.end()); }
	template<typename T>
	cdebug_stream& operator << (T const& val) {
		for(vector<ostream*>::iterator it = m_outs.begin();
				it != m_outs.end();
				++it)
			(**it) << val;
		return *this;
	}
	cdebug_stream& operator << (ostream& (*manip)(ostream&)) {
		for(vector<ostream*>::iterator it = m_outs.begin();
				it != m_outs.end();
				++it)
			(*manip)(**it);
		return *this; 
	}
private:
	vector<ostream*> m_outs;
} cdebug;
 

你可能感兴趣的:(Inherit)