Why are my array of static bools not initialized properly? Only the first one is initialized - I suspect this is because the array is static.
The following MWE was compiled with GCC and is based on a function that I am writing that I have transferred into a main program to illustrate my problem. I have tried with and without c++11. My understanding is because this array is static and initialized to true this should always print the first time I enter my function. So in this MWE it should print once.
#include <iostream>
using namespace std;
const int arraysize = 10;
const int myIndex = 1;
static bool firstTimeOverall = true;
int main()
{
static bool firstCloudForThisClient[arraysize] = {true};
cout.flush();
if (firstCloudForThisClient[myIndex])
{
cout << "I never get here" << endl;
firstCloudForThisClient[myIndex] = false;
if (firstTimeOverall)
{
firstTimeOverall = false;
cout << "But think I would get here if I got in above" << endl;
}
}
return 0;
}
firstCloudForThisClientare initialised totrue?