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;
}
}