It is necessary to create a function, adding elements to the queue, an error is displayed: "The expression must be valid for changing the left-hand value" My function, which I tried to create:

void add(int* integer) { current = new queue; current->value = integer; current->next = NULL; if (last == NULL) { head = current; } else { last->next = current; last = current; } } 

Queue structure:

 struct queue { int value[10]; queue *next; }; 
  • The error is output referring to the line: "current-> value = integer;" - Nick Polica
  • one
    logical - left array, right pointer to int. Although they look similar, and even sometimes interchangeable, they are not compatible types. What exactly flies to add as an argument? - KoVadim
  • as an argument, the array should fly, but even with such a record (void add (int integer [])) the error does not go anywhere - Nick Polica
  • and where is last? something is not visible anywhere - Andrej Levkovitch
  • and current was not announced either. It seems that you took the function of adding from another place, and did not write under your structure - Andrej Levkovitch

2 answers 2

You allocated memory in the structure for an array, and are trying to overwrite the constant address with others.

 struct queue { int value[10]; // память уже выделена, при вызове new queue queue *next; }; 

You need to put a pointer to a structure instead of an array, or copy the memory into an array in a structure.

You can also overload one of the assignment / copy operators in order to copy the data to the structure when the array is assigned to the structure.

  • Thanks for the answer, can you tell where you can get a better look at data structures such as the stack, the queue, and so on? - Nick Polica
  • Unfortunately, I can not recommend you anything from the listed by you, but you should read about constant fields / arrays in structures, and / or classes. - LLENN
  • @NickPolica is a good course that will introduce you to queues, stacks, trees, and some algorithms: courses.openedu.ru/courses ... ... - Andrej Levkovitch
  • Thanks a lot - Nick Polica

In the queue element you have stored ten ints. You must implement the assignment is not a plus, and copying memory.

 #include <string.h> void add(int * integers) { memcpy( & current->value, integers, sizeof(int)*10);