Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: std::sort using class cmp function due to private member? yikes  (Read 1317 times)

0 Members and 1 Guest are viewing this topic.

SpectreNectar

  • Newbie
  • *
  • Posts: 39
    • View Profile
std::sort using class cmp function due to private member? yikes
« on: February 26, 2013, 05:20:36 am »
G'day

This is not directly relevant to SFML by the way but I thought I might receive assistance nevertheless :)

So what I'm trying to do is sort the tiles in my level editor for drawing. For that purpose I use std::sort(). Problem is that it's not working. I pass in a static class function declared like so:

//  Canvas Cell Painter
class Painter {

    private:
       
        ...

    // Place in "grid" that stores Tiles and collision "shapes"
    struct Cell {
        ...
                int    order;         // Drawing order
        ...

        Cell(int ind[], Area* par, sf::Texture* tex) {
            ...
            order = pos[1]-pos[2]; //For draw sorting

            // Add this to parent
            parent = par;
            parent->cells.push_back(this);
                        ...
       }

    }

    ...


    public:

    ...
    static bool cmp_cells(Cell* a, Cell* b);

    ...

};

...and defined like this:

bool Painter::cmp_cells(Painter::Cell* a, Painter::Cell* b) {
    return (a->order<b->order);
}

...and expect it to work when I do:

void Painter::paintbrush(double px, double py, double pz, sf::Texture* texture) {
        ...
        Area* a = new Area(pos, dim);

    // Put a cell in Area
    int zero[3] = { 0,0,0 };
    Cell* c = new Cell(zero, a, texture);

    std::sort(a->cells.begin(), a->cells.end(), Painter::cmp_cells);
        ...

}

But it doesn't =(
Any ideas people?

I'm clueless... thanks for your time anyway

[attachment deleted by admin]
« Last Edit: February 26, 2013, 05:55:37 am by SpectreNectar »

SpectreNectar

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: std::sort using class cmp function due to private member? yikes
« Reply #1 on: February 26, 2013, 06:28:52 am »
Fixed it.

It was due to sorting not being updated.