从对象数组中删除重复项

Delete duplicates from an array of objects

本文关键字:删除 对象 数组      更新时间:2023-10-16

我必须从对象数组中删除重复项,但到目前为止,我的算法给了我错误:

请求'((专辑*)this)中的成员"author"->专辑::歌曲,

指针类型为"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++;
            }
        }
    }
}

有什么办法吗?

使用以下代码,编译器错误应该会消失。

if ( current->author == songs->author && current->title == songs->title
                             ^^^                                ^^^
    && current->year == songs->year && current->length == songs->length)
                             ^^^                               ^^^