Reputation: 1
i try to instantiate a class template with an int Variable. template class:
template <int N>
class GRAPH {
// ...
}
when i try to do this like:
GRAPH<100> mygraph;
it works fine. But when I do this like:
int maxVertices=100;
GRAPH<maxVertices> mygraph;
I get following error:
invalid type in declaration before ';' token
Can someone help me?
Thx
Upvotes: 0
Views: 45
Reputation: 1
Change your code to
const int maxVertices=100;
GRAPH<maxVertices> mygraph;
Template parameters are evaluated at compile time, thus you can only pass a constant expression as template parameter here.
Upvotes: 2