Copio e incollo esempio da vecchio thread
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct immobile{
char topologia;
int dimensione;
};
class myImmobile{
public:
void crea (){
immobili.push_back({'A',32});
immobili.push_back({'B',71});
immobili.push_back({'C',12});
immobili.push_back({'D',45});
immobili.push_back({'E',26});
immobili.push_back({'F',80});
immobili.push_back({'G',53});
immobili.push_back({'H',33});
}
void ordinamento() {
sort (immobili.begin(), immobili.end(), [ ] (immobile i, immobile j) { return i.dimensione < j.dimensione; });
}
void stampa(){
for (auto it = immobili.begin(); it != immobili.end(); it++)
cout << (*it).topologia << ' ' << (*it).dimensione << ' ';
cout << endl;
}
private:
vector<immobile>immobili;
};
int main (void) {
myImmobile test;
test.crea();
test.stampa();
test.ordinamento();
test.stampa();
return 0;
}