Hello everybody!
I'm trying to display the result of difference of two-dimensional vectors using friend overloading. Builder shows the following error after compilation (line 40). What should I change for in my code in order to find the problem?
Thanks in advance.
[C++ Error] 05_Part.cpp(40): E2034 Cannot convert 'double' to 'Vector2D'
#include <iostream.h>
#include <conio.h>
class Vector2D {
double x, y;
friend Vector2D operator- ( const Vector2D &, const Vector2D & );
public:
friend ostream & operator << (ostream & os, const Vector2D & cv)
{ os << cv.x << ',' << cv.y;
return os;
}
};
Vector2D operator- ( const Vector2D & vector1, const Vector2D & vector2 ) {
Vector2D vector_tmp = vector1;
vector_tmp.x -= vector2.x;
vector_tmp.y -= vector2.y;
return vector_tmp;
}
int main()
{
double a1, b1;
double a2, b2;
cout << "Enter the first two-dimensional vector: ";
cin >> a1;
cin >> b1;
cout << "Enter the second two-dimensional vector: ";
cin >> a2;
cin >> b2;
// vector declaration
Vector2D a(a1, b1);
Vector2D b(a2, b2);
cout << "Vector #1: " << a << endl;
cout << "Vector #2: " << b << endl;
// vector difference
Vector2D d = a - b - Vector2D(3.0, 9.0);
cout << "Difference is equal " << d << endl;
getch();
return 0;
}