术语不计算为函数采用 1 个参数错误?



我写这段代码基本上是打乱一个向量,我得到这个错误,我不确定出了什么问题。我已经包括了算法。谢谢!

// Shuffle the vector
random_shuffle(names.begin(), names.end(), rand());
// Prelims
cout << "ROUND PRELIMINATION: BEGIN" << endl;
cout << names[32] << " versus " << names[29] << endl << "Please enter the winner: ";
cin >> winner;
round1.push_back(winner);
cout << endl << names[33] << " versus " << names[30] << endl << "Please enter the winner: ";
cin >> winner;
round1.push_back(winner);
cout << endl << names[34] << " versus " << names[31] << endl << "Please enter the winner: ";
cin >> winner;
round1.push_back(winner);
for (int i = 0; i < 29; i++) {
round1.push_back(names[i]);
}

random_shuffle的最后一个参数必须是返回随机选择值的函数对象。rand()计算结果为int。因此,它不能用作函数的最后一个参数。

以下应该有效。

// Shuffle the vector
random_shuffle(names.begin(), names.end(), [](int n) { return rand()%n; });

最新更新