I have following 2 files implementation.h implementation.cpp
implementation.h is as follows:
#ifndef IMPLEMENTATION_H_
#define IMPLEMENTATION_H_
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <array>
#include <vector>
#include <utility>
#include <queue>
#include <tuple>
#include <algorithm>
#include <cstdlib>
using namespace std;
struct SimpleGraph {
std::map<char, std::vector<char> > edges;
std::vector<char> neighbors(char id);
};
struct GridLocation {
int x, y;
bool operator == (const GridLocation& a, const GridLocation& b) {
return a.x == b.x && a.y == b.y;
}
bool operator != (const GridLocation& a, const GridLocation& b) {
return !(a == b);
}
bool operator < (const GridLocation& a, const GridLocation& b) {
return std::tie(a.x, a.y) < std::tie(b.x, b.y);
}
std::basic_iostream<char>::basic_ostream& GridLocation::operator<<(std::basic_iostream<char>::basic_ostream& out, const GridLocation& loc) {
out << '(' << loc.x << ',' << loc.y << ')';
return out;
}
};
struct SquareGrid{
static std::array<GridLocation, 4> DIRS;
int width, height;
std::set<GridLocation> walls;
SquareGrid(int width_, int height_): width(width_), height(height_) {};
bool in_bounds(GridLocation id);
bool passable(GridLocation id);
std::vector<GridLocation> neighbors(GridLocation id);
};
#endif /* IMPLEMENTATION_H_ */
I have following structs defined: SimpleGraph, GridLocation, SquareGrid
I have defined operator overloading for GridLocation struct
implementation.cpp is as follows:
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <array>
#include <vector>
#include <utility>
#include <queue>
#include <tuple>
#include <algorithm>
#include <cstdlib>
#include "implementation.h"
std::vector<char> SimpleGraph::neighbors(char id) {
return edges[id];
}
bool SquareGrid::in_bounds(GridLocation id) {
return 0 <= id.x && id.x < width
&& 0 <= id.y && id.y < height;
};
bool SquareGrid::passable(GridLocation id) {
return walls.find(id) == walls.end(); // get 2 errors here **
};
std::vector<GridLocation> SquareGrid::neighbors(GridLocation id) {
std::vector<GridLocation> results;
for (GridLocation dir : DIRS) {
GridLocation next{id.x + dir.x, id.y + dir.y};
if (in_bounds(next) && passable(next)) {
results.push_back(next); // get 1 error here -*-
}
}
if ((id.x + id.y) % 2 == 0) {
// aesthetic improvement on square grids
std::reverse(results.begin(), results.end());
}
return results;
}
Errors for ** are
1) in instantiation of member function 'std::__1::set<GridLocation, std::__1::less<GridLocation>, std::__1::allocator<GridLocation> >::find' requested here
2) Invalid arguments '
Candidates are:
std::__1::__tree_const_iterator<GridLocation,std::__1::__tree_node<GridLocation,void *> *,long int> find(const GridLocation &)
'
Errors for -*- are:
1) Invalid arguments '
Candidates are:
void push_back(const GridLocation &)
void push_back(GridLocation &&)
'
I am using Eclipse CDT on mac osx with c++11.
Any help/pointers figuring out the errors above will be appreciated