STL vector question

Hello guys, i am new in this forum.

Suppose i have a class Vertex and a std::vector<A*> v contained in a Mesh object:

I have to build a method where i search the Vector to check if a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef VERTEX_H
#define VERTEX_H
#include <iostream.h>
#include <GL/gl.h>
#include <list>


class Edge;
class Face;

class Vertex
{
    public:
        Vertex() : m_x(0), m_y(0) {}
        Vertex(float x, float y) : m_x(x), m_y(y) {}
        ~Vertex() {}
        float getX() const{return m_x;};
        float getY() const{return m_y;};
        void setX(float x){m_x = x;};
        void setY(float y){m_y = y;};
        void setXY(float x, float y){m_x=x;m_y=y;};

        bool operator==(const Vertex &)const;
        bool operator!=(const Vertex &)const;

    private:
        GLfloat m_x,m_y;
        std::list< Edge* > m_edges;
        std::list< Face* > m_faces;
};

ostream &operator<<( ostream &, const Vertex &);


#endif // VERTEX_H 


and The Mesh class containing the vector:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef MESH_H
#define MESH_H
#include <vector>
#include "Vertex.h"


class Mesh
{
    public:
        Mesh();
        virtual ~Mesh();
        void addVertex(Vertex);
        Vertex getVertex(int index) const{return *(m_vertices[index]);};
        int getVertexCount() const{return (int)m_vertices.size();};


    private:
        std::vector< Vertex* > m_vertices;

};

void drawMesh(const Mesh &mesh);
bool vertexEqualTo(const Vertex *v1, const Vertex *v2);

#endif // MESH_H 


I have to add a method in the Mesh class to check if a given Vertex is already been added. Let's it might look like this:

std::vector<Vertex*>::iterator findVertex(Vertex v);

Inside i'd like to use the find algorithm but it's not so easy. The problem is that the vector's objects aren't Vertices but pointers to Vertices. Using the find() algo directly to the vector elements will just check (and eventually return an iterator)if there is 1 element containing the same address as the one i am going to search for.

Instead of course i wanna check if there is a pointer pointing to the Vertex v i am going to search for.

Looking on the web i spotted a snip where they use the "find" algo with 4 arguements (1 of 'em is a nice function) but seems like this kind of "find" doesn't exist. Morover find_if won't help me.

Can u show me a way to solve this problem?
Thank a lot :D
Is there a particular reason why you are storing pointers to the vertices in the vector?
The vector class will be able to handle holding Vertex objects directly if you want it to.
Topic archived. No new replies allowed.