开发者

How to use class templates as function arguments?

开发者 https://www.devze.com 2022-12-29 14:50 出处:网络
I have a class declared along the lines of template<int a, int b> class C { public: array[a][b]; } and I want to use it as argument in a function like this:

I have a class declared along the lines of

template<int a, int b>
class C {
public:
    array[a][b];
}

and I want to use it as argument in a function like this:

bool DoSomeTests(C &c1, C &c2);

but when I compile, it tells me 'use of class template requires template argument list.' I tried

template<int a, int b>
bool DoSomeTests(C &c1, C &c2)开发者_Python百科;

but I get the same error. How can I fix this?


You need to provide arguments to the class template C in the declaration of DoSomeTests:

template<int a, int b>
bool DoSomeTests(C<a, b> &c1, C<a, b> &c2);

Both the class template C and your function template DoSomeTests take two int template parameters but the fact that you want to map them from the function template to C can't be inferred by the compiler.

0

精彩评论

暂无评论...
验证码 换一张
取 消