I receive the following error on declaring a vector of Point
in the code shown (see reference to class template instantiation std::vector<Point,std::allocator<Point>>
being compiled):
Severity Code Description Project File Line Suppression State Error C2558 class 'Point': no copy constructor available or copy constructor is declared 'explicit' AI assignment 1 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\xmemory 671
#include <iostream>
#include<vector>
using namespace std;
int dx, dy, sx, sy;
class Point
{
public:
int x;
int y;
float g;
float h;
Point()
{}
Point(int s, int d)
{
x = s;
y = d;
h = pow(pow(x - dx, 2) + pow(y - dy, 2), 1 / 2);
}
Point(Point &p)
{
x = p.x;
y = p.y;
g = p.g;
h = p.h;
}
bool operator == (Point p)
{
if (p.x == x && p.y == y)
return true;
else
return false;
}
};
class RoutePlaner
{
vector<vector<char>>grid;
int mapsize;
Point start;
Point destination;
int no_of_obstacles;
vector<Point> obstacles;
void generate_random_obstacles(int num)
{
for (int i = 0; i < num; i++)
{
int k = rand() % mapsize;
int j = rand() % mapsize;
Point p(i, j);
grid[j][k] = 'X';
obstacles.push_back(p);
}
}
public:
RoutePlaner(int m, Point s, Point d, int no)
{
mapsize = m;
start = s;
destination = d;
no_of_obstacles = no;
vector<char> vec(mapsize, '.');
for (int i = 0; i < mapsize; i++)
{
grid.push_back(vec);
}
//Setting start and destination
grid[start.x][start.y] = 'S';
grid[destination.x][destination.y] = 'D';
// setting obstacles
generate_random_obstacles(no_of_obstacles);
}
};
int main()
{
}
How should I declare a vector of class objects? How do I resolve the error?