Why size_t arguments in template declaration need to be const?

Posted by ArunSaha on Stack Overflow See other posts from Stack Overflow or by ArunSaha
Published on 2010-04-24T16:40:34Z Indexed on 2010/04/24 16:43 UTC
Read the original article Hit count: 202

Filed under:
|

I can have

std::bitset< 10 > bitsetA;

or

const size_t LengthB = 20;
std::bitset< LengthB > bitsetB;

without any problem.

But, if the length is not const

size_t LengthC = 30;
std::bitset< LengthC > bitsetC;  // Line 30, say

I face the following compilation error

'LengthC' cannot appear in a constant-expression
template argument 1 is invalid

What is the reason for that?

What would be the problem, for compiler and for user code, if line 30 was to be accepted? Is it because LengthC might have some alias?

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates