求助
  • 板块学术版
  • 楼主gongxuanwen
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/12/18 10:15
  • 上次更新2023/10/24 07:21:35
查看原帖
求助
577963
gongxuanwen楼主2022/12/18 10:15

这是两个随机数的函数,但是uniform_int_distribution<>在random库中定义时要求类型一定是整型,但是_Ty = int不被看做是整型,所以编译出错。uniform_real_distribution<>同理。请问有没有办法解决这个问题?

template <typename _Ty = int>
inline const _Ty random(const _Ty MIN = (numeric_limits<_Ty>::min)(), const _Ty MAX = (numeric_limits<_Ty>::max)())
{
	static uniform_int_distribution<_Ty> random_pool(MIN, MAX);
	return random_pool(seed);
}

template <typename _Ty = double>
inline const _Ty frandom(const _Ty MIN = (numeric_limits<_Ty>::min)(), const _Ty MAX = (numeric_limits<_Ty>::max)())
{
	static uniform_real_distribution<_Ty> frandom_pool(MIN, MAX);
	return frandom_pool(seed);
}
[Error] static assertion failed: result_type must be a floating point type
[Error] static assertion failed: template argument must be an integral type
2022/12/18 10:15
加载中...