# Error in compiling, plz help

**URL:** <https://forum.codewithmosh.com/t/error-in-compiling-plz-help/24497>\
**Category:** C++\
**Created:** [January 9, 2024, 7:27am UTC](https://forum.codewithmosh.com/t/error-in-compiling-plz-help/24497 "2024-01-09T07:27:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zeus](https://avatars.discourse-cdn.com/v4/letter/z/a4c791/32.png) [@Zeus](https://forum.codewithmosh.com/u/Zeus)\
**Post date:** [January 9, 2024, 7:27am UTC](https://forum.codewithmosh.com/t/error-in-compiling-plz-help/24497/1 "2024-01-09T07:27:49Z")

</div>

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

```auto

#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

```auto
#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:

```auto
#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

 ![Screenshot 2024-01-09 162729](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/4/44169293279e90344c62b10ea3ab9ab3dcf7d83b.png)

---

<div class="post-metadata">

**Author:** ![POMPOMBALLS](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/pompomballs/32/6610_2.png) [@POMPOMBALLS](https://forum.codewithmosh.com/u/POMPOMBALLS)\
**Post date:** [January 9, 2024, 9:49am UTC](https://forum.codewithmosh.com/t/error-in-compiling-plz-help/24497/2 "2024-01-09T09:49:15Z")

</div>

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

````auto
```
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.

---

<div class="post-metadata">

**Author:** ![Zeus](https://avatars.discourse-cdn.com/v4/letter/z/a4c791/32.png) [@Zeus](https://forum.codewithmosh.com/u/Zeus)\
**Post date:** [January 9, 2024, 10:57am UTC](https://forum.codewithmosh.com/t/error-in-compiling-plz-help/24497/3 "2024-01-09T10:57:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![POMPOMBALLS](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/pompomballs/32/6610_2.png) [@POMPOMBALLS](https://forum.codewithmosh.com/u/POMPOMBALLS)\
**Post date:** [January 9, 2024, 1:56pm UTC](https://forum.codewithmosh.com/t/error-in-compiling-plz-help/24497/4 "2024-01-09T13:56:56Z")

</div>

It is a link error that I too experienced.

I have posted a solution for it:

> [@Undefined Reference](https://forum.codewithmosh.com/t/undefined-reference/23342/6):
>
> Your files must be known to the linker. LNK2019 (in Visual Studio) is a linking error for unresolved external symbol(s). Make sure your file is included in the project as shown (again, Visual Studio). The code works as it should. For more information, look [here](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) (discussion).

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](https://stackoverflow.com/questions/47416178/cout-not-working-with-ostream-header-file#:~:text=The%20reason%20of%20why%20this,but%20not%20the%20ostream%20class.).

Reply if there is still an error.

---

<div class="post-metadata">

**Author:** ![Zeus](https://avatars.discourse-cdn.com/v4/letter/z/a4c791/32.png) [@Zeus](https://forum.codewithmosh.com/u/Zeus)\
**Post date:** [January 10, 2024, 4:46am UTC](https://forum.codewithmosh.com/t/error-in-compiling-plz-help/24497/5 "2024-01-10T04:46:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![POMPOMBALLS](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/pompomballs/32/6610_2.png) [@POMPOMBALLS](https://forum.codewithmosh.com/u/POMPOMBALLS)\
**Post date:** [January 10, 2024, 7:08am UTC](https://forum.codewithmosh.com/t/error-in-compiling-plz-help/24497/6 "2024-01-10T07:08:47Z")

</div>

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).
