ZuK, why do you have the protected section? It should be private.
style, refer this as well : How to deal with operator overloading?
Printable View
ZuK, why do you have the protected section? It should be private.
style, refer this as well : How to deal with operator overloading?
Agreed. Protected doesn't make any sense in this example. There is not much to inherit from that class. Even public would make more sense.Quote:
Originally Posted by exterminator
Kurt
A better implementation would of course be:;)Code:ostream & operator << ( ostream & ostr, const rect & r ) {
ostr << '+';
for ( int i = 0; i < r.w_; ++i )
ostr << '-';
ostr << '+' << '\n';
for ( int j = 0; j < r.h_; ++j ) {
ostr << '|';
for ( int i = 0; i < r.w_; ++i )
ostr << ' ';
ostr << '|' << '\n';
}
ostr << '+';
for ( int i = 0; i < r.w_; ++i )
ostr << '-';
ostr << '+' << '\n';
return ostr;
}
Could be further improved by using one of Strings Constructors...
Code:for ( int i = 0; i < r.w_; ++i )
ostr << '-';
becomes....
ostr << string('-', r.w_);
etc.....