Error in compiling, plz help

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

Verify your code that you have provided here and put the whole code of each file between backticks ( ` )

```
Your code goes here
```

Also add the error screenshot or copy the error message and add it just like the code.

It is difficult to recreate any issue if our code is not same as yours.

1 Like

Yeah I copied and pasted the code as it is from my pc

It is a link error that I too experienced.

I have posted a solution for it:

Read the thread.

If that does not work then try replacing ostream header with iostream.
It is probably compiler dependent. I had suggested using ostream in another post but later I found that it was not working.

Reply if there is still an error.

Nah i tried everything even went on to yt but its not working. I also tried to watch some YT tutorials. The thing is none of the other overloaded operator is causing this problem only the ‘<<’ operator,

Is there a problem with the code or smth?

I ran your code with suggested edits and it is working. Your errors are linking errors.

If you have tried those suggestions and they still do not work then try recreating the project from your workspace or reinstalling your compiler (VS Installer).