### How to equal using assignment operators

it shows insertion operators error but works when i use string

 ``123456789101112131415161718192021222324252627282930313233`` `````` #include #include #include using namespace std; class vector { public: int x ,y; vector(){}; vector(int a ,int b) { x=a; y=b; } //: x(a),y(b){} vector vector::operator= (vector b1) { vector b2; b2.x=b1.x; b2.y=b2.y; return (b2); } }; int main () { vector b1 (3,1) , b2(1,3); vector b3; b2= b1; cout<
cout << b2.x << " " << b2.y;
I think this is right, though I may have overlooked something:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` ``````#include #include using namespace std; class vector { public: int x ,y; vector(){}; vector(int a ,int b) { x=a; y=b; } vector & operator=(const vector & b1) { x = b1.x; y = b1.y; return *this; } friend ostream & operator<<(ostream & os, const vector & v); }; ostream & operator<<(ostream & os, const vector & v) { os << '(' << v.x << ',' << v.y << ')'; return os; } int main () { vector b1 (3,1) , b2(1,3); vector b3; b3 = b2; b2 = b1; cout << b2 << " "; cout << b3; }``````
Thank you everythings clear good programming can't we do that without using operator overload for`<<`
 can't we do that without using operator overload for<<

Of course we can. I gave you that as a free gift, take it if it's useful, ignore it if it isn't.
Topic archived. No new replies allowed.