I am using a array of pointers to objects and wish to sort them using std::sort(). However, I've noticed that sort() cannot do this and seems to only work on non-pointer arrays.
Is there a way I can keep the array of pointers and somehow make std::sort work?
// working version
#include <algorithm>
usingnamespace std;
int main()
{
int Ar[] = {5,1,2,4};
sort( Ar, Ar+sizeof(Ar)/sizeof(int) );
return 0;
}
// Non working version - This is what I want to get working
#include <algorithm>
usingnamespace std;
int main()
{
int Ar[] = { newint(5), newint(1), newint(2), newint(4) };
sort( Ar, Ar+sizeof(Ar)/sizeof(int*) );
return 0;
}