2010-05-05 22 views
1

正如您可能已经猜到的,我不想对指针地址进行排序,而是对对象/数据进行排序。如何对指针的CArray进行排序?

目前,我有一个这样的数组:

CArray <ReadObject *> readCollecion; 

和我有点像说:完美地与keySortFunction

std::sort(readCollecion.GetData(), readCollecion.GetData()+readCollecion.GetSize(), keySortFunction); 

作品。

问题是我需要指向我的对象的指针,因为我需要修改它们已经在数组中的对象。我想我需要和阵列是这样的:

CArray <ReadObject *> readCollecion; 

现在我可以改变对象后,但我的排序似乎无法处理这一点。

+0

你原始对象应该可能是'CArray readCollection' – 2010-05-05 15:24:39

+0

因此,我认为你正在改变你指向的对象,以改变排序顺序?也就是说,你是否在更改用于确定排序顺序的成员? – andand 2010-05-05 15:24:55

+0

假设你打算使用ReadObject *,也许你应该改变keySortFunction? – 2010-05-05 15:49:47

回答

0

如果我正确理解你的问题,所有你需要做的是改变从const ReadObject&keySortFunction参数类型const ReadObject*做出的功能进行适当的修改,以使用->,而不是.

0
bool keySortFunction(const ReadObject& o1, const ReadObject& o2) 
{ 
    return ...; 
} 

CArray <ReadObject> readCollecion; 
std::sort(readCollecion.GetData(), readCollecion.GetData()+readCollecion.GetSize(), eySortFunction); 

... 

CArray <ReadObject*> readCollecion2; 
std::sort(readCollecion2.GetData(), readCollecion2.GetData()+readCollecion2.GetSize(), [](ReadObject* o1, ReadObject* o2) 
{ 
    return keySortFunction(*o1, *o2); 
}); 
相关问题