所以,我有兩個類:調用ostream的友元函數
class Base {
private:
int number;
public:
friend ostream & operator<<(ostream & output, const Base &n);
}
ostream & operator<<(ostream & output, const Base &n) {
output<<n.a<<endl;
return output;
}
class Child : Base {
private:
int second;
public:
friend ostream & operator<<(ostream & output, const Child &n);
}
ostream & output<<(ostream & output, const Child &n) {
output<<n.second<<Base:: ????<<endl;
return output;
}
我的問題是,我怎麼能調用基類的友元函數從子類來輸出它的內容:
output<<n.second<<Base:: ????<<endl
感謝提前:)
爲什麼啊你爲什麼要通過指針? 'static_cast (n)'非常好,不太冗長。 –
2012-04-28 20:46:01
@MatthieuM。固定。 – David 2012-04-28 21:16:01