Reputation: 191
I declare a table of booleans and initialize it in main()
const int dim = 2;
bool Table[dim][dim];
int main(){
Table[dim][dim] = {{false,false},{true,false}};
// code
return 0;
}
I use mingw
compiler and the builder options are g++ -std=c++11
.
The error is
cannot convert brace-enclosed initializer list to 'bool' in assignment`
Upvotes: 17
Views: 62962
Reputation: 3724
You can use memset(Table,false,sizeof(Table))
for this.it will work fine.
Here is your complete code
#include <iostream>
#include <cstring>
using namespace std;
const int dim = 2;
bool Table[dim][dim];
int main(){
memset(Table,true,sizeof(Table));
cout << Table[1][0] << "\n";
// code
return 0;
}
Upvotes: 0
Reputation: 41
First, you are trying to assign a concrete element of array instead assigning the full array. Second, you can use initializer list only for initialization, and not for assignment.
Here is correct code:
bool Table = {{false,false},{true,false}};
Upvotes: 4
Reputation: 409166
Arrays can only be initialized like that on definition, you can't do it afterwards.
Either move the initialization to the definition, or initialize each entry manually.
Upvotes: 9