Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert Brace-enclosed initializer list

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`

like image 504
user3481693 Avatar asked Apr 02 '14 09:04

user3481693


2 Answers

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}};
like image 114
Tanya Borisova Avatar answered Nov 12 '22 10:11

Tanya Borisova


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.

like image 30
Some programmer dude Avatar answered Nov 12 '22 10:11

Some programmer dude