Struct with char vector

0

So folks, I created this struct

typedef struct{
    int inicio;
    int tamanho;
    int fim;
    char *elementos[50];
}Fila;

And I intend to create a vector of char, just as I created several times a vector of integers. But it is not working at the time of implementing the queue function.

Fila* criarFila(int tamanho){
    Fila* novaFila = new Fila;
    novaFila->tamanho = tamanho;
    novaFila->inicio = -1;
    novaFila->fim = -1;
    novaFila->elementos = new char[tamanho];

    return novaFila;
}

At compile time, I get the error:

listar.cpp:66:22: error: incompatible types in assignment of ‘char*’ to   ‘char* [50]’
  novaFila->elementos = new char[tamanho];
                      ^

Does anyone understand why you are generating this error?

    
asked by anonymous 13.06.2016 / 07:01

1 answer

0
char *elementos[50];

So you're creating an array of 50 char-type pointers. Probably what you want is just a pointer (there the new char will work):

char *elementos;

Or, if you want an array of fixed size:

char elementos[50];

In this case, it will be allocated along with the struct (no need to use new).

    
18.06.2016 / 16:54