C++ error

When I run my code, It appears an error in this part saying: "error: expected ';' before 'newCais'"
Can anyone help me on this? Thank you

1
2
3
4
5
6
7
8
9
10
  vector<cais> readcais() {
  vector<string> caisFile = readFile("Cais.txt");
  vector<cais> cais;

  for (int i=1; i < caisFile.size(); i++){
    vector<int> line = splitLine(caisFile[i], ';');
    cais newCais = createcais(line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7], line[8], line[9], line[10], line[11], line[12] , line[13], line[14], line[15], line[16], line[17]);
    cais.push_back(newCais);
  }
    return cais;
The problem is that you use the same name for both variable and class. When the compiler sees "cais" on line 7 it sees a variable but a variable does not make sense there.
But I have another vector, with the exact same structure that didn't give me any kind of error:


vector<encomenda> readEncomendas() {
vector<string> encomendasFile = readFile("Encomendas.txt");
vector<encomenda> encomendas;

for (int i=1; i < encomendasFile.size(); i++){
vector<int> line = splitLine(encomendasFile[i], ';');

encomenda newEncomenda = createEncomenda(line[0], line[1], line[2], line[3]);
encomendas.push_back(newEncomenda);
}

return encomendas;
}

vector<local> readLocais() {
vector<string> locaisFile = readFile("Locais.txt");
vector<local> locais;

for (int i=1; i < locaisFile.size(); i++){
vector<int> line = splitLine(locaisFile[i], ';');
local newLocal = createlocal(line[0], line[1], line[2], line[3]);
locais.push_back(newLocal);
}
return locais;
But I have another vector, with the exact same structure that didn't give me any kind of error:
You dont': encomenda and encomendas is different.
Thank you very much!!! It works now!
Topic archived. No new replies allowed.