I am building my old CPP codes from 20+ years ago, but g++ gives build error. Can someone explains me what has changed? Thanks. (It was fine in turbo C)
error:
t_overload.cpp:8:40: error: no matching constructor for initialization of 'Point'
Point operator+(Point& v) { return Point(x+v.x, y+v.y); }
^~~~~~~~~~~~~~~~~~~
cpp file:
#include <stdio.h>
struct Point {
int x, y;
// Point(Point& v) {set(v.x, v.y);} // build okay without this line; error if uncomment
Point(int a, int b) {set(a,b);}
void set(int a, int b) {x=a, y=b;}
Point operator+(Point& v) { return Point(x+v.x, y+v.y); }
};
int main() {
Point a(1,2);
Point b(a);
Point c = a + b;
printf("%d %d\n", c.x, c.y);
}