这对您来说可能很容易,但我还没有真正了解引用资料。我不明白为什么这行不通。请告诉我正确的样式。
template <typename T>
void shuffle(T (&array)[], size_t len){};
我试着这样调用它:
uint_fast8_t dirBag[4]
Random::shuffle(dirBag, sizeof(dirBag)/sizeof(decltype(dirBag[0])));
错误是:
Error 1 error C2784: 'void Random::shuffle(T (&)[],size_t)' : could not deduce template argument for 'T (&)[]' from 'uint_fast8_t [4]'
最佳答案
尝试:
template <typename T, size_t N>
void shuffle(T (&array)[N])
{
};
此外,在函数体内,您有数组的大小:N
。如果您必须将尺寸作为参数传递,我当然认为您可以,但参数将是独立的。
站点注意:根据您的函数名称判断,您可能还会对此感兴趣:
uint_fast8_t dirBag[4];
// ...populate your array...
std::random_shuffle(std::begin(dirBag), std::end(dirBag));
关于c++ - 对数组的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15047979/