Beginner A* Code with an error

I have started programming, and I tried doing a path finding algorithm. (The drawPath is an auxiliary function to be able to see the path found.) There seems to be a problem with the code, but I seem to not be able to find it. I would appreciate any comments about the code, whether it is a mistake or an improbable part.
This is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
  Position.h
#pragma once
class Position {
private:
	float _x, _y;
public:
	Position();
	Position(float x, float y);
	
	void setPosition(float x, float y);

	float getX();
	float getY();
};

 Position.cpp
#include "Position.h"
Position::Position() : _x(0), _y(0)
{}
Position::Position(float x, float y) : _x(x), _y(y)
{}

void Position::setPosition(float x, float y) 
{
	_x = x;
	_y = y;
}

float Position::getX()
{
	return _x;
}
float Position::getY()
{
	return _y;
}

Point.h
#pragma once
#include "Position.h"

class Point {
private:
	Position* _position;
	Point* _parent;
	bool _walkable;
	float g, h, f;

public:
	Point();
	Point(Position* position, bool walkable);

	Position* getPosition();
	Point* getParent();

	float getG();
	float getH();
	float getF();
	float distanceBetween(Point* end);

	bool hasParent();
	bool isWalkable();

	void setParent(Point* parent);
	void setWalkable(bool walkable);
	void calculateG();
	void calculateF(Point* destination);
	void calculateH(Point* destination);
};

Point.cpp
#include "Point.h"
#include <cmath>

Point::Point() : _walkable(false)
{
	_position = &Position();
}
Point::Point(Position* position, bool walkable) : _position(position), _walkable(walkable)
{}

Position* Point::getPosition()
{
	return _position;
}
Point* Point::getParent()
{
	return _parent;
}

float Point::getG()
{
	return g;
}
float Point::getH()
{
	return h;
}
float Point::getF()
{
	return f;
}

bool Point::hasParent()
{
	bool hasParent = true;
	if (_parent != nullptr) {
		hasParent = false;
	}
	return hasParent;
}
bool Point::isWalkable()
{
	return _walkable;
}

void Point::setParent(Point* parent)
{
	_parent = parent;
}
void Point::setWalkable(bool walkable)
{
	_walkable = walkable;
}
void Point::calculateF(Point* destination)
{
	calculateG();
	calculateH(destination);
	f = g + h;
}
void Point::calculateH(Point* destination)
{
	h = distanceBetween(destination);
}
void Point::calculateG()
{
	g = 0;
	if (hasParent()) {
		_parent->calculateG();
		g = _parent->g + distanceBetween(_parent);
	}
}
float Point::distanceBetween(Point* end)
{
	return std::sqrt(std::pow(end->getPosition()->getX() - getPosition()->getX(), 2) + std::pow(end->getPosition()->getY() - getPosition()->getY(), 2));
}

Map.h
#pragma once
#include "Point.h"
#include <list>

class Map {
private:
	std::list<Point*> points;
	float _width, _height;
	float _tileSize;
public:
	Map();
	Map(double width, double height, double tile_size);

	float getTileSize();

	Point* closestPoint(Position* position);

	std::list<Point*> closePoints(Point* point);

	void drawPath(std::list<Point*> path);
};

Map.cpp
#include "Map.h"
#include <iostream>
Map::Map() : _width(0), _height(0), _tileSize(1)
{
	float w = 0, h;
	while (w <= _width) {
		h = 0;
		while (h <= _height) {
			points.push_back(&Point(&Position(w, h), true));
			h += _tileSize;
		}
		w += _tileSize;
	}
}
Map::Map(double width, double height, double tile_size) : _width(width), _height(height), _tileSize(tile_size)
{
	int w = 0, h;
	while (w <= _width) {
		h = 0;
		while (h <= _height) {
			points.push_back(&Point(&Position(w,h),true));
			h =  h + _tileSize;
		}
		w = w + _tileSize;
	}

}

float Map::getTileSize()
{
	return _tileSize;
}

Point* Map::closestPoint(Position* position)
{
	std::list<Point*>::iterator i;
	for (i = points.begin(); i != points.end(); i++) {
		if ((*i)->getPosition()->getX() >= position->getX() - _tileSize/2 && (*i)->getPosition()->getX() <= position->getX() + _tileSize/2) {
			if ((*i)->getPosition()->getX() >= position->getX() - _tileSize/2 && (*i)->getPosition()->getX() <= position->getX() + _tileSize/2) {
				return (*i);
			}
		}
	}
}

std::list<Point*> Map::closePoints(Point* point)
{
	std::list<Point*> list;
	std::list<Point*>::iterator i;
	for (i = points.begin(); i != points.end(); i++) {
		if ((*i)->isWalkable()) {
			if ((*i)->getPosition()->getX() >= point->getPosition()->getX() - _tileSize && (*i)->getPosition()->getX() <= point->getPosition()->getX() + _tileSize) {
				if ((*i)->getPosition()->getX() >= point->getPosition()->getX() - _tileSize && (*i)->getPosition()->getX() <= point->getPosition()->getX() + _tileSize) {
					list.push_back(*i);
				}
			}
		}
	}
	return list;
}


void Map::drawPath(std::list<Point*> path)
{
	int x = 0;
	float height = 0;
	bool FOUND;
	std::list<Point*>::iterator i,t;
	for (i = points.begin(); i != points.end(); i++) {
		if ((*i)->getPosition()->getY() != height) {
			std::cout << std::endl;
		}
		FOUND = false;
		for (t = path.begin(); t != path.end(); t++) {
			if ((*i) == (*t)) {
				FOUND = true;
				break;
			}
		}
		if (FOUND) {
			std::cout << "*";
		}
		else if((*i)->isWalkable()){
			std::cout << " ";
		}
		else {
			std::cout << "X";
		}
		height = (*i)->getPosition()->getY();
	}
}

PathFinder.h
#pragma once
#include "Map.h"
class PathFinder {
private:
	Map* _map;
	
	Point* lowest_f(std::list<Point*> set);
	std::list<Point*> reconstructPath(Point* destination);

public:
	PathFinder();
	PathFinder(Map* map);
	
	std::list<Point*> findPath(Point* start, Point* destination);

	void drawPath(std::list<Point*> path);
};

PathFinder.cpp
#include "PathFinder.h"
#include <climits>

PathFinder::PathFinder()
{
	_map = &Map();
}
PathFinder::PathFinder(Map* map) : _map(map)
{}

void PathFinder::drawPath(std::list<Point*> path)
{
	_map->drawPath(path);
}
Point* PathFinder::lowest_f(std::list<Point*> set)
{
	int min = INT_MIN;
	Point* aux = 0;
	std::list<Point*>::iterator i;
	for (i = set.begin(); i != set.end(); i++) {
		if ((*i)->getF() < min) {
			min = (*i)->getF();
			aux = (*i);
		}
	}
	return aux;
}
std::list<Point*> PathFinder::reconstructPath(Point* destination)
{
	std::list<Point*> list;
	Point* current = destination;
	
	do {
		list.push_front(current);
		current = current->getParent();
	} while (current->hasParent());

	return list;
}

std::list<Point*> PathFinder::findPath(Point* start, Point* destination)
{
	std::list<Point*> closedSet = {}, openSet = { start }, neighbor;
	std::list<Point*>::iterator i, w, t;
	Point* current = start;
	Point* auxiliar;
	float tentative_g;
	bool FOUND;

	current->calculateF(destination);

	while(!openSet.empty())
	{
		current = lowest_f(openSet);
		if (current == destination) {
			return reconstructPath(current);
		}
		openSet.remove(current);
		closedSet.push_front(current);

		neighbor = _map->closePoints(current);
		for (i = neighbor.begin(); i != neighbor.end(); i++) {
			for (t = closedSet.begin(); t != closedSet.end(); t++) {
				if ((*i) == (*t)) {
					continue;
				}				
			}

			tentative_g = current->getG() + current->distanceBetween((*i));
			FOUND = false;
			for (w = openSet.begin(); t != openSet.end(); t++) {
				if ((*i) == (*t)) {
					FOUND = true;
					break;
				}
			}
			if (!FOUND) {
				(*i)->setParent(current);
				(*i)->calculateF(destination);
				openSet.push_back(*i);
			}
			else if (tentative_g >= (*i)->getG()){
				continue;
			}
			(*i)->setParent(current);
			(*i)->calculateF(destination);
		}
	}
	return {};
	
}

Main.cpp
#include "PathFinder.h"

int main() {
	Map map(100, 100, 10);
	PathFinder pathfinder(&map);
	
	pathfinder.drawPath(pathfinder.findPath(map.closestPoint(&Position(0, 0)), map.closestPoint(&Position(260, 100))));
	system("PAUSE");
}
Line 44: Why is position a pointer? Doesn't a point always have a position?

Line 47: What are f, h, and h?

Line 104: Your hasParent() returns true when there ISN'T a parent. Why have this function at all when the caller could instead just call getParent() and test it themself?

Line 155: Why a list of pointers instead of a list of Points?

Line 168: When passing a container, it's always a good idea to pass it by reference (or const reference). Otherwise each time you call the function, the compiler will make a copy of the whole container.

Line 180: Here's your bug and it's related to my questions about using pointers instead of values. You're pushing the address of a temporary variable onto the list. The variable will be deleted it's memory free to be reused anytime after line 180 finishes. Furthermore, the Position whose address you're passing to the Point is also a temporary.

So by the time you reach line 181, your program is toast.

Change the pointers I mentioned to instances and see how it works then.
I am a beginner. When i tried my first code.
#include <iostream.h>
#include <conio.h>
int main()
{
clrscr()
cout <<"My First Programming.";
getch();
return 0;
}

above code i tried and when compiled then the error is
1 22 E:\Dev-Cpp\Untitled1.cpp [Error] iostream.h: No such file or directory

what is my fault? what to do now?
Please help
@shahfrid open your own thread for your question.
Please read: Welcome -- read before posting!
http://www.cplusplus.com/forum/beginner/1/
Topic archived. No new replies allowed.