#include <iostream>
using namespace std;
class Point {
int x, y;
public:
void set (int a, int b) { x = a; y = b; }
Point operator+ (const Point& d) {
Point s;
s.set (x + d.x, y +d.x);
return s;
}
friend ostream& operator << (ostream& o, const Point& d);
};
inline ostream& operator << (ostream& o, const Point& d) {
return o << "(" << d.x << ", " d.y << ")\n";
}
int main()
{
Point s, t;
s.set (2, 5);
t.set (3, 1);
cout << s+t;
return 0;
}
VC下编译
C:\Documents and Settings\Administrator\桌面\b.cpp(17) : error C2248: 'x' : cannot access private member declared in class 'Point'
C:\Documents and Settings\Administrator\桌面\b.cpp(5) : see declaration of 'x'
C:\Documents and Settings\Administrator\桌面\b.cpp(17) : error C2146: syntax error : missing ';' before identifier 'd'
C:\Documents and Settings\Administrator\桌面\b.cpp(17) : error C2248: 'y' : cannot access private member declared in class 'Point'
C:\Documents and Settings\Administrator\桌面\b.cpp(5) : see declaration of 'y'
C:\Documents and Settings\Administrator\桌面\b.cpp(17) : error C2297: '<<' : illegal, right operand has type 'char [3]'
C:\Documents and Settings\Administrator\桌面\b.cpp(25) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
b.obj - 5 error(s), 0 warning(s)
请问该怎么改