//*** Example 5 (a) -- nonvirtual streaming
class X
{
/*...ostream is never mentioned here...*/
};
ostream& operator<<( ostream& o, const X& x )
{
/* code to output an X to a stream */
return o;
}
//Here's the second:
//*** Example 5 (b) -- virtual streaming
class X
{
/*...*/
public:
virtual ostream& print( ostream& ) const;
};
ostream& X::print( ostream& o ) const
{
/* code to output an X to a stream */
return o;
}
ostream& operator<<( ostream& o, const X& x )
{
return x.print( o );
}
NameLookupAndInterfacePrinciple2
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.