我的类上有一组指针,我需要对其进行排序。排序工作正常,我只是不确定,我只是切换课堂上的参考,还是整个课堂......
我的代码是这样的:
ITEM *items = new ITEM[set.pathc];
...
bool change = true;
while( change )
{
change = false;
for( i = 0; i < set.pathc-1; i++ )
{
if( compare( items+i, items+i+1, set.order, set.order_asc ) )
{
ITEM temp;
temp = *(items+i);
items[i] = items[i+1];
items[i+1] = temp;
change = true;
}
}
}
那么我的代码切换只是指针(我的意思是分配对象的地址)还是整个对象(比如复制所有私有变量,它不需要“=”运算符吗?)?
我想只切换指针,因为我想它会更快,我试过这样
ITEM *temp
temp = item+i;
item[i] = item+i+1;
item[i+1] = temp;
但它没有用:-/(我什至无法编译代码)
提前感谢您的解释:)