I'm having the weirdest error and I've no idea what I'm doing wrong.
template <bool X>
struct A {
int x;
};
template <bool X>
struct B : public A<X> {
B() { x = 3; } // Error: 'x' was not declared in this scope.
};
I don't understand how it's possible that I cannot see x
from B
, given that I'm inheriting A
publicly.
At the same time, this code compiles:
template <bool X>
struct A {
int x;
};
template <bool X>
struct B : public A<X> {};
int main() {
B<false> b;
b.x = 4;
};
I'm compiling with g++ 7.0.1.
Edit: It seems that if I reference the full-name of x
, the code compiles, as in:
B() { A<X>::x = 3; }
But why?