Asad S. Malik
Asad S. Malik

Reputation: 157

Passing in template class reference as parameter in c++

So I have something like:

template<int X>
class foo {

char a[X];

...

}

and I have another class 'bar' which contains a function like:

void execute(foo &b); 

which should perform tasks on the char array in foo but it gives me an error saying it's a template class but using something like:

void execute(foo<int> &b); 

gives an error as well. I'm not sure how exactly to pass it as the only thing which doesn't give me an error is if I statically give it a value like:

void execute(foo<4> &b);

Thanks a lot!

Upvotes: 2

Views: 1703

Answers (1)

ForEveR
ForEveR

Reputation: 55887

Non-type template parameters should be known at compile-time. Right call for function will be something like

template<int N>
void execute(foo<N>& b);

// call
foo<4> b;
execute(b);

Upvotes: 7

Related Questions