Hi all,

first time posting here, I need some help with this, as my knowledge of c++ is shaky at best.

I have points defined like this:

struct Point

  double x, y, z;


I have a 2d vector filled with vectors of these points:

vector< vector<Point> > possible_neurons;

I want to look for duplicates in possible_neurons, which I think means that all points in two vectors must be in the same order and have the same values ( x, y, z ). My code doesn't sort them when it populates possible_neurons and I am really unsure as to how I can compare the points. Any help is appreciated.


8 Years
Discussion Span
Last Post by NathanOliver

well you can overload the operator= function for Point

bool operator=(const Point & rhs, const Point & lhs)
    return ((rhs.x == lhs.x) && (rhs.y == lhs.y) && (rhs.z == lhs.z));

Edited by NathanOliver: n/a


I'm sure Nathan Oliver meant to suggest you could overload the equals operator, ==, for the class rather than the assignment operator, =, that he typed.

To detect duplicates you don't have to sort the points if you don't want to. If you were to sort the points, and it can be a nice learning exercise if you do it, I would suggest a nest sort where you sort first by the x coordinate, then within the points with the same x coordinate you first sort by the y coordinates, and then you sort by the z coordinates for each group of points that have the same x and y coordinates. A similar logic would allow you to overload the < operator for the class.

Edited by Lerner: n/a


Whats wrong with this :

vector< vector<Point> > possible_neurons
vector< vector<Point> > possible_neurons_second_copy;
possible_neurons_second_copy = possible_neurons;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.