考虑以下代码段:
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";
}
};
有什么办法可以更改Print
为ObjectInterface
标准的“ std::ostream& operator<<
”输出类型?我不能让它工作。
编辑:我基本上是想弄清楚我是否可以friend
使用virtual
.