01/10/2018, 17:15
Lỗi private khi truy cập input và output operators
Hàm operator input/output của e nó báo lỗi là private không thể truy cập là sao? Friend có thể truy cập mà.
Mọi người giúp e với ạ.
#include <bits/stdc++.h>
using namespace std;
class retangle {
private:
double width, height;
string color;
public:
retangle();
retangle( double, double, string );
void setWidth( double );
void setHeight( double );
void setColor( string );
friend ostream &operator << ( ostream& , retangle & );
friend istream &operator >> ( istream& , retangle & );
};
retangle::retangle(): width(0) , height(0) , color("whiile"){}
retangle::retangle( double wid, double hei, string col ){
width = wid;
height = hei;
color = col;
}
void retangle::setWidth( double _width ){
width = _width;
}
void retangle::setColor( string _color ){
color = _color;
}
void retangle::setHeight( double _height ){
height = _height;
}
ostream& operator << ( ostream &output, const retangle &a){
output << "Style of retangle is :";
output<<"
Height is: "<<a.height << endl <<"Width is : " << a.width << endl <<"Color is: "<< a.color << endl;
}
istream & operator >> ( istream &input, const retangle &n){
cout << "Set retangle :
";
cout<<"
Height is: "; input >>n.height ;
cout<<"
Width is: "; input >>n.width;
cout<<"
Color is: "; input >>n.color;
}
int main(){
retangle retangle1;
return 0;
}
Bài liên quan
Bạn chưa có giá trị trả về cho input và output.
Thêm return input vs return output vào là được.