64,646
社区成员
发帖
与我相关
我的任务
分享
// .h改成
#ifndef RECTANGLE_H
#define RECTANGLE_H
class rectangle
{
public:
rectangle(double Lent,double wid)
:length(Lent) ,width(wid){ }
virtual ~rectangle() { }
double getLength()const;
double getWidth()const;
double area()const;
void print(ostream & out)const;
private:
double length;
double width;
};
ostream& operator <<(ostream& out,const rectangle& rec);
#endif
然后再 cpp 里加上
ostream& operator <<(ostream& out,const rectangle& rec)
{
rec.print(out);
return out;
}