美文网首页
cpp操作符重载

cpp操作符重载

作者: 汇源可乐 | 来源:发表于2020-06-12 13:26 被阅读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;
    }
    }
    

    相关文章

      网友评论

          本文标题:cpp操作符重载

          本文链接:https://www.haomeiwen.com/subject/qpmgtktx.html