Deadlocker
Programmer
Hi !
Here is what I want to do :
I have a class AElement that stores many information and particularly that implements a getX() function.
I have many AElements objects and I want to access them via some pointers. So I want to have a list of AElements because this data structures implements data structures and methods that are usefull for me.
Everything works fine until there, I can push, pop and print the list without any problem since the beginning of the afternoon (6 hours ago).
But I want to classify the elements regarding the returning value of getX(). SO I discovered that the list implements a "sort" facility we can use and "personalize" with our own comparison method. That's the point I'm facing so many troubles...
My code :
My comparison operator is as below :
template <class T>
struct sort_by_ptr
{
bool operator()(const T* left, const T* right)const
{
return ((left->getStartPos())->getX()) <= ((right->getStartPos())->getX());
}
};
and I call through :
list<AElement*> *aelist;
aelist = new list<AElement*>;
aelist->sort(sort_by_ptr<AElement>());
Thanks a lot for any comment !
Here is what I want to do :
I have a class AElement that stores many information and particularly that implements a getX() function.
I have many AElements objects and I want to access them via some pointers. So I want to have a list of AElements because this data structures implements data structures and methods that are usefull for me.
Everything works fine until there, I can push, pop and print the list without any problem since the beginning of the afternoon (6 hours ago).
But I want to classify the elements regarding the returning value of getX(). SO I discovered that the list implements a "sort" facility we can use and "personalize" with our own comparison method. That's the point I'm facing so many troubles...
My code :
My comparison operator is as below :
template <class T>
struct sort_by_ptr
{
bool operator()(const T* left, const T* right)const
{
return ((left->getStartPos())->getX()) <= ((right->getStartPos())->getX());
}
};
and I call through :
list<AElement*> *aelist;
aelist = new list<AElement*>;
aelist->sort(sort_by_ptr<AElement>());
Thanks a lot for any comment !