//*** 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
最新推荐文章于 2011-12-23 11:20:44 发布