Код ниже не может быть скомпилирован. Однако, когда я удаляю «const» из функции Point & of friend, этот код оказывается скомпилированным. Кто-нибудь может объяснить причину?
class Point
{
public:
Point(double x, double y);
Point operator+(const double& add);
friend Point operator+(const double& add, const Point& p){return p+add;}
private:
double px, py;
};
Point::Point(double x, double y): px(x), py(y){}
Point Point::operator+(const double& add){
return(Point(px+add, py+add));
}
int main(){}