I wrote a template function, that should take a reference to array of const elements, that has certain size. But for some reason the compiler says that this function doesn't match, when I call it
#include<iostream>
struct Node
{
int key, left, right;
};
template <int N>
bool isCorrect(const Node (&nodes)[N])
{
// doesn't matter
return true;
}
int main ()
{
int n;
std::cin >> n;
Node nodes[n];
std::cout << (isCorrect(nodes) ? "CORRECT" : "iNCORRECT") << '\n';
return 0;
}
It gave me a rather mysterious error message that I couldn't decipher:
"candidate template ignored couldn't match **Node** against **Node"**.
I pretty sure that template can be used to determine array size, like I'm trying to do, but this fails.
Is this due to the fact that I use a non-primitive type?
Yes, I know I can use vector and avoid this problem altogether. But I really want to know what the hell is going on when compiler can't match a type against itself.
What I can do to avoid this strange message in future?