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.

thanks!

Recommended Answers

All 4 Replies

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));
}

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.

Whats wrong with this :

vector< vector<Point> > possible_neurons
vector< vector<Point> > possible_neurons_second_copy;
possible_neurons_second_copy = possible_neurons;

Yes I did mean to type ==. The brain is a little laggy today. Maybe I should run a de-frag ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.