I created n objects from the Stock class and assigned a value for the integer instance variable expectancy. This value is different for each object (stock). I want to order objects descending according to expectancy. How can I achieve that?
1 2
Stock* stock = new Stock [n];
stock[counter].expectancy = ............;
if the object is large and you need to sort it multiple ways, you may want a container of pointers to the original data and sort the pointers instead of the real data. This is more of a real world answer, than homework.
I used this code but it doesn't work and I don't know why. Could you please help? sort(stock[0].expectancy, stock[lastElementIndex].expectancy, greater<int>());