Look at my code below. I made a class Vector2D. I overloaded the + operator and the * operator. In the main function I test these 2 overloaded operators. The only thing I want to add to this is the following: I want to overload the >> operator(?) so when I use >>, I can type in a vector. (so the x and the y component). Then I want to overload the << operator(?) so when I use <<, the program will return me my inputted vector.
#include <iostream>
using namespace std;
class Vector2D
{
public:
Vector2D();
Vector2D(double X = 0, double Y = 0)
{
x = X;
y = Y;
};
double x, y;
Vector2D operator+(const Vector2D &vect) const
{
return Vector2D(x + vect.x, y + vect.y);
}
double operator*(const Vector2D &vect) const
{
return (x * vect.x) + (y * vect.y);
}
};
int main()
{
cout << "Adding vector [10,10] by vector [5,5]" << endl;
Vector2D vec1(10, 10);
Vector2D vec2(5, 5);
Vector2D vec3 = vec1 + vec2;
cout << "Vector = " << "[" << vec3.x << "," << vec3.y << "]" << endl;
cout << "Dot product of vectors [5,5] and [10,10]:" << endl;
double dotp = vec1 * vec2;
cout << "Dot product: " << dotp << endl;
return 0;
}
The only problem is, I dont know how to do this. Could someone help me^.^?? Thanks in advance.