Hi
i tried to do some training and write '==' operator to compare between two vectors
but i got this error
Error 1 error LNK2005: "bool __cdecl operator==(class vector,class vector)" (??8@YA_NVvector@@0@Z) already defined in Source.obj c:\Users\Sarbast\documents\visual studio 2013\Projects\Overloading Vector\Overloading Vector\Vector.obj Overloading Vector
Vector.h
#include <iostream>
using namespace std;
#ifndef VECTOR_H
#define VECTOR_H
class vector{
private:
int x, y, z;
public:
vector();
vector(int, int, int);
void DisplayVector();
int GetX() const {
return x;
}
int GetY() const{
return y;
}
int GetZ() const {
return z;
}
};
bool operator==(const vector v1, const vector v2){
if ((v1.GetX() == v2.GetX()) &&
(v1.GetY() == v2.GetY()) &&
(v1.GetZ() == v2.GetZ()))
return true;
else
return false;
}
#endif
Vector.cpp
#include "Vector.h"
vector::vector(){
x = 0;
y = 0;
z = 0;
}
vector::vector(int x1, int y1, int z1){
x = x1;
y = y1;
z = z1;
}
void vector::DisplayVector(){
cout << "X = " << x << endl;
cout << "Y = " << y << endl;
cout << "Z = " << z << endl;
}
Source.cpp
#include <iostream>
#include "Vector.h"
using namespace std;
int main()
{
vector v1(3, 5, 7);
v1.DisplayVector();
vector v2(3, 5, 8);
v2.DisplayVector();
if (v1 == v2)
cout << "The vectors are same " << endl;
else
cout << "They are different " << endl;
system("PAUSE");
return 0;
}