Reputation: 48021
Microsoft VC++ 2010 gives an error on this code:
template <int D, typename T>
void Foo(T x[D]) {
// details omitted
}
int main() {
float x[3];
Foo(x); // C2784: could not deduce template argument for 'T [D]' from 'float [3]'
return 0;
}
The same code passes muster with gcc and clang.
Is this a bug with VC++ 2010?
If it is a bug:
Foo<3, float>
?If it is not a bug:
Is there an extension to gcc and clang that allows them to resolve the template arguments?
I've greatly simplified the actual code down to this small example. I've tried it on other compilers, but I don't presently have access to newer Microsoft compilers. I've found similar questions on SO, but none that specifically address this case.
Upvotes: 4
Views: 330
Reputation: 52601
A parameter of type T x[D]
is equivalent to T x[]
aka T* x
. D
cannot be deduced from it. Make it void Foo(T (&x)[D])
- you are passing a reference to an array this way.
Upvotes: 6