Rare error (Extended initializer lists) [closed]

1

Good people,

I just had an error in this fairly simple code, which I had never seen before.

#include <iostream>
#include <iomanip>
#include <string.h>
#include <stdio.h>
const int tam = 10;
using namespace std;

struct Votante {
int DNI;
char nombre[40];
bool presente;
};

void carga(Votante x[]){
string nom;

for (int i=0; i<tam; i++){
    cin >> x[i].DNI;
    cin >> nom;
    strcpy(x[i].nombre, nom.c_str());   
}
}

void carga2 (Votante x[], FILE *z){
z = fopen("Padron.bin","wb");

for (int e = 0;e < tam;e++){
    fwrite(&x[e],sizeof(Votante),1,z);
}
fclose(z);
}


int main{   
Votante a[tam];
FILE *t;

carga(a);
carga2 (a, t);
}

And I get this error (Line 35 is the int main one)

35  9[Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11

I never saw this error in what I've been compiling all this time, and I searched and did not find out what it could be about.

Greetings

    
asked by Uso Compartido 10.10.2017 в 00:47
source

2 answers

3

That kind of error occurs with the new initialization style using { } , but in your case, maybe you think you're trying to do that kind of initialization, because you forgot the ( ) to define main() as function. (he's seeing it as an entire variable)

    
answered by 10.10.2017 в 01:12
2

You are declaring an object of type int with name main :

int main{   
Votante a[tam];
FILE *t;

carga(a);
carga2 (a, t);
}

When adding the keys after the name of the object, the compiler believes that you want to use a list to initialize it. Surely you wanted a main function that returns int , so:

//      vv <--- Parametros de la funcion
int main(){   
Votante a[tam];
FILE *t;

carga(a);
carga2 (a, t);
return 0; // <--- retorno de la funcion
}
    
answered by 10.10.2017 в 09:03