I make the following declarations:
class Servo {
protected:
static const int maxServos = 16;
static Servo servos[maxServos]; //Array declaration
};
Servo Servo::servos[Servo::maxServos]; //Array definition
...and it compiles, which is great ! But I don't understand why it compiles because it seems to me that maxServos is protected and I am using it in a global scope when I define the array. I tried using it in another global context and indeed I did get a compile error:
int main() {
std::cout << Servo::maxServos; //This will not compile.
}
So what is going on ? Is the whole definition of the array somehow scoped by the namespace qualifying the array ? Is it a compiler glitch ?
I am using g++ -std::c++11 on a Raspberry PI using Lubuntu 16.04 O/S.