如何解决如何调用包含 random_device 的函数生成随机数?
每次调用chooseDealer 函数时都会出错。这是由于我传递的参数。如何调用使用“random_devices”生成随机数的函数。
#include <iostream>
using namespace std;
#include <random>
random_device rd; // obtain a random number from hardware
mt19937 gen(rd()); // seed the generator
uniform_int_distribution<> distr(0,4); // define the range
struct card
{
char i;
string suit;
};
struct player
{
string id[4];
int t[4];
// card* cardsinhand;
};
void chooseDealer(player p,random_device rd)
{
cout << "The dealer will be chosen from the following entries: \n";
for(int i=0;i<4;i++)
{
cout << p.id[i] << endl;
}
cout << "The dealer is: " << distr(gen) << endl; // generate numbers
}
void Deal_and_Tumps(player p,random_device rd)
{
cout << "Player " << distr(gen) << "has chosen the suit ";
}
int main()
{
player p;
cout << "Enter the ID of all the four players respectively: \n";
for(int i=0;i<4;i++)
{
cin >> p.id[i];
}
chooseDealer(p,rd);
}
我得到的错误是在 main() 中,它指出使用了已删除的函数
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。