[英]std::array template function
I have a simple function to shuffle elements in an std::array我有一个简单的 function 来洗牌 std::array 中的元素
template <typename T, uint size>
void Shuffle(std::array<T, size> &arr) {
for (uint i = 0; i < arr.size() - 1; i++)
{
std::swap(arr[i], arr[Random(i, arr.size())]);
}
}
make/g++ doesn't like the way I'm declaring this, giving the error "variable or field Shuffle declared void." make/g++ 不喜欢我声明的方式,给出错误“变量或字段随机播放声明无效”。 From what I've found, this is probably an irrelevant error message, but I can't figure out what's actually wrong here.
根据我的发现,这可能是一条无关紧要的错误消息,但我无法弄清楚这里到底出了什么问题。
uint
doesn't match the type of the 2nd template parameter of std::array
, which is std::size_t
. uint
与std::array
的第二个模板参数的类型不匹配,即std::size_t
。 This causes template argument deduction failing when calling Shuffle
, unless you specify template arguments explicitly.这会导致调用
Shuffle
时模板参数推导失败,除非您明确指定模板 arguments。
You should declare the 2nd template parameter with type std::size_t
.您应该使用
std::size_t
类型声明第二个模板参数。 eg例如
template <typename T, std::size_t size>
void Shuffle(std::array<T, size> &arr)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.