A) Do you need to write a sorting algorithm to do the sorting on the class member variable?
OR
B) Do you want to know how to sort the class in STL with a class member variable?
For either case, I would recommend writing a functor to help with the comparisons on your class member:
struct CompareYourClassMemberXLess
{
bool operator()(const YourClass &lhs, const YourClass &rhs)
{
if (&lhs == &rhs)
return false;
return lhs.GetX() < rhs.GetX();
}
};
Create an instance of your functor before you sort:
CompareYourClassMemberXLess CmpXLess;
Now in your sort algorithm, when you want to compare the two values in, you can call the varible CmpXLess like a function to determine where it fits in the search order.
YourClass a;
YourClass b;
CmpXLess(a,b);
for STL use it like this:
std::sort(a.begin(), b.begin(), CompareYourClassMemberXLess());
BTW, feel free to change the obnoxiously long names to something that makes sense in your program. The names will not change the functionality.