#include <string>
// 가상함수가아닌것을가상함수처럼보이게하기.
class object
{
public:
virtual string ToString() const
{
return string("object");
}
friend ostream& operator<<( ostream& os, const object& o )
{
return os << o.ToString();
}
};
class Point : public object
{
public:
virtual string ToString() const
{
return string("Point");
}
};
void main()
{
object* pp = new Point;
cout << *pp << endl;
object o;
cout << o << endl;
Point p;
cout << p << endl;
}
Tag | C++