Hi I am an amatuer coder and I am going through the advanced section of the C++ course but in the exercise for overloading’+’ i keep getting the eror of unresolved external can someone look at my code and help me plz. Thank You.
main file
#include "Point.h"
#include <iostream>
using namespace std;
int main(){
Point first = { 1,2 };
Point second = { 1,2 };
Point third = (first + second);
cout << third;
}
header file
#ifndef POINT_H
#define POINT_H
#include <ostream>
using namespace std;
class Point
{
public:
bool operator==(const Point& point);
Point(int x, int y);
Point getPoint(int x , int y);
Point operator+(const Point& point) const;
Point operator+(const int& value) const;
int getX() const;
int getY() const;
void setX(int x);
void setY(int y);
private:
int x;
int y;
};
ostream& operator<<(const ostream& stream,const Point& point);
#endif // POINT_H
cpp file:
#include "Point.h"
#include <ostream>
using namespace std;
bool Point::operator==(const Point& point)
{
return (x == point.x && y == point.y);
}
Point::Point(int x, int y)
{
this->x = x;
this->y = y;
}
Point Point::getPoint(int x, int y)
{
return Point(x, y);
}
Point Point::operator+(const Point& point) const
{
return Point(getX() + point.getX(), getY() + point.getY());
}
Point Point::operator+(const int& other) const
{
return Point(getX() + other, getY() + other);
}
int Point::getX() const
{
return x;
}
int Point::getY() const
{
return y;
}
void Point::setX(int x)
{
this->x = x;
}
void Point::setY(int y)
{
this->y = y;
}
ostream& operator<<(ostream& stream, const Point& point)
{
stream << "("<< point.getX() << "," << point.getY() << ")";
return stream;
}
again thanks for the help
Here is the error message