【发布时间】:2009-04-11 20:02:19
【问题描述】:
考虑以下 sn-p:
struct ObjectInterface
{
virtual ~ObjectInterface() {}
virtual void Print(std::ostream& target) const = 0;
};
struct Foo : ObjectInterface
{
virtual void Print(std::ostream& target) const
{
target << "Foo";
}
};
struct Bar : ObjectInterface
{
virtual void Print(std::ostream& target) const
{
target << "Bar";
}
};
有没有办法将ObjectInterface 中的Print 更改为标准的“std::ostream& operator<<”输出类型?我不能让它工作。
编辑:我基本上是想弄清楚我是否可以让friend 与virtual 一起工作。
【问题讨论】: