我必须从一个对象数组中删除重复项,但到目前为止,我的算法给了我错误:
请求'((专辑*)本身)中的成员'作者' - >专辑::歌曲',
是指针类型'Song *'(也许你打算使用' - >'?)|
所以这就是代码:
void Album::deleteDuplicates()
{
Song* current , *end = songs + top - 1;
for ( current = songs + 1; songs < end; songs++, current = songs + 1 )
{
while ( current <= end )
{
if ( current->author == songs.author && current->title == *songs.title
&& current->year == *songs.year && current->length == *songs.length)
{
*current = *end--;
}
else
{
current++;
}
}
}
}
任何想法如何解决?
答案 0 :(得分:0)
使用以下代码,编译器错误应该消失。
if ( current->author == songs->author && current->title == songs->title
^^^ ^^^
&& current->year == songs->year && current->length == songs->length)
^^^ ^^^