#include <iostream>
#include <math.h>
usingnamespace std;
class vec {
public:
int x, y;
vec (int a, int b) {
x = a;
y = b;
}
vec operator + (vec& o) { return vec(x+o.x, y+o.y); }
vec operator - (vec& o) { return vec(x-o.x, y-o.y); }
vec operator * (vec& o) { return vec(x*o.x, y*o.y); }
vec operator * (int& o) { return vec(x*o, y*o); }
voidoperator += (vec& o) { x += o.x; y += o.y; }
voidoperator -= (vec& o) { x -= o.x; y -= o.y; }
voidoperator *= (vec& o) { x *= o.x; y *= o.y; }
voidoperator *= (int& o) { x *= o; y *= o; }
int dot (vec& o) { return x*o.x + y*o.y; }
double length (void) { return sqrt( (x*x) + (y*y) ); }
};
ostream& ostream::operator << (vec& val) {
this << "(" << val.x << ", " << val.y << ")" << endl;
returnthis;
}
int main () {
vec x (3, 4);
cout << x;
return 0;
}
What should happen is that '(3, 4)' should be printed to the console. What actually happens is that the code doesn't compile. It gives the error "template-id `operator<< <>' for `std::ostream& std::basic_ostream<char, std::char_traits<char> >::operator<<(vec&)' does not match any template declaration"