user98188
user98188

Reputation:

How to use class templates as function arguments?

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);

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

Upvotes: 1

Views: 2080

Answers (1)

CB Bailey
CB Bailey

Reputation: 791391

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.

Upvotes: 6

Related Questions