我为我的程序洗牌歌曲,但我有点困惑,因为当我尝试编译器告诉我,我不能比较我的结构到一个int。我想知道你可能会想什么?C++:如何洗牌动态数组指针?
struct Songs //my struct
{
string title;
string artist;
string mem;
};
Songs *ptr;
ptr = new Songs[25]; //dynamic array
,所以我告诉U中的结构和PTR以及继承人的功能IM遇到问题..
void shuffle (Songs song[], Songs *ptr, string title, string mem, string artist, int num)
{
for (int i=0; i<(num); i++)
{
int r = i + (rand() % (num-i)); // Random remaining position.
int temp = ptr[i]; ptr[i] = ptr[r]; ptr[r] = temp; //this isnt working
} //but its logically sound?
for (int c=0; c<n; c++)
{
cout << ptr[c] << " "; // Just print
}
}
这是* not *指针数组。另外,你的函数中有很多未使用的参数。故意地? – 2012-02-29 09:38:32
啊为未使用的参数道歉 – gamergirl22 2012-02-29 09:50:47