class Parent
{
...
friend ostream& operator<<(ostream&, const Parent&);
};
class Child : public Parent
{
...
friend ostream& operator<<(ostream&, const Child&);
};
ostream& operator<< (ostream& os, const Parent& p)
{
os << ... ;
return os;
}
ostream& operator<< (ostream& os, const Child& c)
{
os << c.Parent << ... ; // can't I access the subobject on this way?
return os;
}
如何在 Child 运算符中调用 Parent 运算符?这只是给了我错误“无效使用 Parent::Parent”