定义类的ostream输出

class Tree
{
    int height;
public:
    Tree(int treeHeight):height(treeHeight){}
    ~Tree(){
        cout<<"*";
    }

    friend ostream& operator<<(ostream& os, const Tree* t){
        return os<<"Tree height is: "<<t->height<<endl;
    }
};
原文地址:https://www.cnblogs.com/wiessharling/p/3063568.html