View Full Version : [c++ niubbo] identificatore non dichiarato
Ciao ragazzi!
Ho questo codice
........
for (blabla *i = this; i->next != NULL; i = i->next);
i->next = new blabla(s, server);
i->next->prev = i;
.......
Su Visual Studio 6.0 viene compilato, mentre qui a casa dove ho visual studio 8 trial mi dice
error C2065: 'i': identificatore non dichiarato
error C2065: 'i': identificatore non dichiarato
La domanda è, perchè VS6 lo compila e VS8 trial no? :eek:
Scusate, sono proprio all'inizio, non uccidetemi :flower:
tomminno
16-10-2009, 19:10
Il secondo blocco, quello dove dà errore è al di fuori del ciclo for :D
Visual Studio 6 non era propriamente aderente allo standard (oltretutto è contemporaneo dello standard C++).
VS8 (2005) ha sicuramente ragione, lo scope di una variabile dichiarata in un for finisce con il for.
Che versione sarebbe la trial? Ti consiglio di usare la versione Express di Visual Studio 2008 (VS9)
Grazie tomminno, in effetti cercando un altro pò con google è venuto fuori :
error C2065: 'i' : undeclared identifier
This happens because you're trying to compile a vs2005 programm with vs2008, i is declared in a header of a for loop but used after the for block, with2005 the scope of a variable decleared in a for header was in the same code block as the header, but in ANSI C it's scope is limited to the for block, you can fix by placing the declaration of "i" out side the for header like this:
int i; for(;i<whatever;i++){...}
E' corretto?
Chiedo scusa, ma come già detto, non sono assolutamente pratico di programmazione. E ciò non mi è ancora chiaro. :-(
La trial sarebbe : Visual Studio Team System Trial 30Days.
Di nuovo grazie.
tomminno
23-10-2009, 18:48
Grazie tomminno, in effetti cercando un altro pò con google è venuto fuori :
error C2065: 'i' : undeclared identifier
This happens because you're trying to compile a vs2005 programm with vs2008, i is declared in a header of a for loop but used after the for block, with2005 the scope of a variable decleared in a for header was in the same code block as the header, but in ANSI C it's scope is limited to the for block, you can fix by placing the declaration of "i" out side the for header like this:
Mmmh mi sembrava che l'ultimo compilatore a soffrire del bug fosse il 2003. Il 2005 mi sembrava già aderente agli standard.
E' corretto?
Si ma devi ricordarti che poi fuori dal for la variabile i vale whatever, e nel caso citato inizialmente sarebbe corretto.
La trial sarebbe : Visual Studio Team System Trial 30Days.
Di nuovo grazie.
Ti conviene usare la Express, per lo meno puoi usarla anche dopo i 30 giorni :)
tomminno Ti ringrazio infinitamente per la pazienza.
Sei stato veramente gentile!
GRAZIE!
Potete chiudere il topic, problema risolto grazie a tomminno ed ho capito una cosa nuova :muro: :)
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.