1
I’m trying to create a queue with structs, but it’s not working the assignment section on lines 17/18, I can’t find the error. The logic I’m using is correct?
error: request for member 'nome' in 'FilaAluno', which is of pointer type 'aluno' (maybe you meant to use '->' ?) FilaAluno[fimfila].nome = FilaAluno.nome;
I’m using Atom with Myngw.
#include <iostream>
using namespace std;
#define max_fila 2
struct aluno {
char nome [100];
int cod;
int turma;
} ;
bool enfileirar(aluno FilaAluno[], int &i, int &fimfila){
if (fimfila == max_fila){
std::cout << "fila cheia" << '\n';
return false;
}
else{
FilaAluno[fimfila].nome = FilaAluno[i].nome; //problema
FilaAluno[fimfila].cod = FilaAluno[i].cod; //problema
FilaAluno[fimfila].turma = FilaAluno[i].turma;
fimfila++;
}
return true;
}
int main(){
aluno FilaAluno [max_fila]; //fila
int inifila = 0;
int fimfila = 0;
for (int i = 0; i < max_fila; i++) {
/* code */
std::cout << "Codigo:" << '\n';
std::cin >> FilaAluno[i].cod;
std::cout << "Nome:" << '\n';
std::cin >> FilaAluno[i].nome;
std::cout << "Turma:" << '\n';
std::cin >> FilaAluno[i].turma;
if(enfileirar (FilaAluno, i, fimfila)){
std::cout << "Item adicionado com sucesso!" << '\n';
}
}
}
What do you mean, "it’s not working"? Also, mark with a comment the lines with problem, to avoid that people have to count the lines of code.
– Pablo Almeida
@pabloalmeida, I just corrected it. It’s not working because it’s giving an attribution error, says it’s invalid. I also don’t know if my logic is correct, because the material of the college is not very good.
– Tiago Silveira
Thank you, Tiago, but it would be good if you put the exact text of the error.
– Pablo Almeida
@pabloalmeida, I put the message presented.
– Tiago Silveira