I'm trying to do something like this:
#include <iostream>
#include <array>
using namespace std;
template <size_t A>
class Test {
public:
typedef array<int, A> TestType;
};
template <size_t A>
void foo(Test<A>::TestType t) {
cout << "test\n";
}
int main() {
Test<5>::TestType q;
foo(q);
return 0;
}
but foo doesn't compile. In gcc I get
prog.cpp:12:19: error: variable or field ‘foo’ declared void
void foo(Test<A>::TestType t) {
^
prog.cpp:12:28: error: expected ‘)’ before ‘t’
void foo(Test<A>::TestType t) {
while in Visual Studio 2010 I get
error C2975: 'Test' : invalid template argument for 'A', expected compile-time constant expression
I don't understand what I am doing wrong, as A is a compile-time constant. What should I change?