cpp操作符重载

2020-06-12  本文已影响0人  汇源可乐
class Parent{
char * name;
public:
ostream &operator<<(ostream &os, const Parent&parent) {
    os << "name: " << parent.name;
    return os;
}
}

class Child:public Parent{
private:
   char* childName;
public:
ostream &operator<<(ostream &os, const Child &child) {
    os << static_cast<const Parent&>(child) << " childName: " << childName;
    return os;
}
}
上一篇下一篇

猜你喜欢

热点阅读