Hi!
I cannot figure out, why is the following code incorrect:
const int array[] = { 1 };
const int var = 1;
template<int I>
struct Blah {};
int main() {
Blah<var> b1;
Blah<array[0]> b2; // ERROR!
}
I know that template arguments can only be constant expressions. But I don't
understand why isn't 'array[0]' treated as a constant expression. It seems
to me that if an array is const and the index is a constant expression
(e.g. 0), then the whole expression is constant. I can't imagine, how a
compiler can NOT know, what's the value of array[0] during compile-time.
I would be grateful, if you explained me this issue.
Thanks in advance! (I hope, you understand me :))
--
Pozdrawiam, Andrzej