[英]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: 并且我还有另一个类“ bar”,其中包含类似以下功能:
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: 它应该在foo中的char数组上执行任务,但是给我一个错误,说它是模板类,但是使用了类似的东西:
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! 非常感谢!
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.