我有以下代码,它采用未排序的歌曲和艺术家列表,并对它们进行排序和显示。
int main()
{
SongList totalList; // has a public 2d array 'unsortedSongs' variable
char songs[100][80] =
{
{"David Bowie 'Ziggy Stardust'",},
{"Smokey Robinson 'You've Really Got A Hold On Me'",},
{"Carole King 'You've Got A Friend'",},
// many more songs here totaling to 100
{"Joni Mitchel 'A Case Of You'",},
{"Prince 'Kiss'"}
};
memcpy(&totalList.unsortedSongs, &songs, sizeof(songs)); // this causes a segmentation fault
totalList.displaySortedList();
return 0;
}
我几乎直接从这里的示例中提取了 memcpy 的代码,所以我很困惑为什么这不起作用。有人可以帮我解决这个问题吗?
编辑:
这是 SongList 的初始化
class SongList
{
public:
char unsortedSongs[100][80];
public:
void displaySortedList();
void sortList();
string rearrange(char[]);
string getSongsForArtist(int*);
};