I have a piece in my program that compares the average distance from a group of points (the ‘Some_points’ structure). According to my idea, it takes a vector of such structures, and sorts them by the average distance from another point using std::sort and the comparator function. But the compiler constantly produces many errors (as I understand it, they are from the sort function itself).
If anything, I’m new to C++. I’m just trying to make 3D in the terminal.
struct Point
{
float x, y;
float z = 10;
float distants = 0;
bool operator == (const Point lhs) {
if (std::abs(lhs.x) == std::abs(x) && std::abs(lhs.y) == std::abs(y) && std::abs(lhs.z) == std::abs(z)) {
return true;
}
else {
return false;
}
}
float distantsion(Point pl) {
distants = sqrtf(powf((pl.x - x), 2) + powf((pl.y - y), 2) + powf((pl.z - z), 2));
return distants;
}
bool operator < (const Point& lhs) {
if (distants < lhs.distants) {return true;}
else {return false;}
}
};
struct Some_points
{
std::vector<Point> points;
float distance = 0;
void get_distants(Point pl) {
for (auto i : points){
distance += i.distantsion(pl);
}
distance /= points.size();
}
bool operator < (const Some_points lhs) {
return (distance < lhs.distance);
}
};
std::vector<Some_points> sort_objects(std::vector<Some_points>& o_pool, Point player) {
for (auto i :o_pool) {
i.get_distants(player);
}
std::sort(o_pool.end(), o_pool.begin());
return o_pool;
};
I tried to rewrite Some_points a little, but the error remained
EdyNamic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4