Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Sort Vector of Objects (c++)

Name: Anonymous 2009-01-20 5:26

Hello,

I have the following code for sorting a Vector of vertices by their 'x' coordinate value:

(Vertex.h)
...
bool operator<(const Vertex& other) { return (this->x < other.x); }

(elsewhere)
    std::vector<Vertex*> vertices;
...    //vector is populated
    std::sort(vertices.begin(), vertices.end());

This doesn't do the desired sorting, for whatever reason.
Is something wrong with my code?

Name: Anonymous 2009-01-20 6:50


    bool compareVertices(Vertex const* a, Vertex const* b)
    {
        return (a->getX() < b->getX());   //problem line
    }


"'Vertex::getX' : cannot convert 'this' pointer from 'const Vertex' to 'Vertex &'", so says VC++.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List