2009-10-12 6 views
11

Come dice il titolo, non sono sicuro del motivo per cui sto ricevendo questo errore. Ho messo insieme un test.cpp che è simile a questa struttura e funziona perfettamente. Inoltre, oltre al problema del vettore, c'è l'altro problema relativo a "protetto", che non è nemmeno nel codice. Penso che "protetto" sia una macro, quindi non dire cosa c'è. Sono nuovo di QT, quindi probabilmente "sto sbagliando". Questo è certamente ciò che suggerisce il compilatore.Aiuto con errore: ISO C++ vieta la dichiarazione di 'vettore' senza tipo

In file included from DrvCrystalfontz.cpp:8: 
LCDText.h:28: error: ISO C++ forbids declaration of 'vector' with no type 
LCDText.h:28: error: expected ';' before '<' token 
LCDText.h:30: error: ISO C++ forbids declaration of 'vector' with no type 
LCDText.h:30: error: expected ',' or '...' before '<' token 
LCDText.h:46: error: expected ':' before 'protected' 
LCDText.h: In constructor 'LCDText::LCDText(int, int, int, int, int, int, int, QObject*)': 
LCDText.h:33: error: expected '{' at end of input 
scons: *** [DrvCrystalfontz.o] Error 1 
scons: building terminated because of errors. 

Ecco il codice. Ho numerato le linee annotate nell'errore.

#ifndef __LCD_TEXT__ 
#define __LCD_TEXT__ 

#include <vector> 
#include <QObject> 

#include "LCDBase.h" 
#include "WidgetText.h" 
#include "WidgetBar.h" 
#include "WidgetHistogram.h" 
#include "WidgetIcon.h" 
#include "WidgetBignums.h" 
#include "WidgetGif.h" 

class LCDText: public LCDBase, public virtual QObject { 
    Q_OBJECT 
    protected: 
     char *LayoutFB; 
     char *DisplayFB; 
     int GOTO_COST; 
     int CHARS; 
     int CHAR0; 
     int LROWS; 
     int LCOLS; 
     int DROWS; 
     int DCOLS; 
     vector<vector<char *> > chars; // Line 28 
     void (*TextRealWrite) (const int row, const int col, const char *data, const int len); 
     void (*TextRealDefchar) (const int ascii, const vector<char *> matrix); // Line 30 
    public: 
     LCDText(int rows, int cols, int xres, int yres, int _goto, int chars, 
      int char0, QObject *parent) : LCDBase(xres, yres), QObject(parent); // Line 33 
     ~LCDText(); 
     void TextInit(int rows, int cols); 
     void TextBlit(int row, int col, int height, int width); 
     void TextClear(); 
     void TextClearChars(); 
     void TextGreet(); 
     void TextDraw(WidgetText widget); 
     void TextBarDraw(WidgetBar widget); 
     void TextHistogramDraw(WidgetHistogram widget); 
     void TextIconDraw(WidgetIcon widget); 
     void TextBignumsDraw(WidgetBignums widget); 
     void TextGifDraw(WidgetGif widget); 
    public signals: // Line 46 
     void SpecialCharChanged(int ch); 
    public slots: 
     void TextSpecialCharChanged(int ch); 
}; 

#endif 

risposta

31

Il vettore risiede nello spazio dei nomi std. Devi fare uno dei seguenti modi:

Prepend tipo con lo spazio dei nomi:

std::vector<std::vector<char *> > chars; 

dire al compilatore che si sta utilizzando vettore dal namespace std

using std::vector; 
vector<vector<char *> > chars; 

Oppure, dire al compilatore stai usando lo spazio dei nomi std, che porterà tutto (non consigliato, vedi commenti)

using namespace std; 
+20

Per favore, per amore dell'umanità, non "usare il namespace XXX" in un file di intestazione. Farai piangere ogni altro programmatore che lo incontra. –

+1

D'accordo, ma si può anche dire alle persone le opzioni;) – MichaelM

+1

Bene quindi includere questa opzione: usando std :: vector; Lo preferisco nel file .cpp immediatamente dopo l'inclusione. Salva legando std :: dappertutto * e * documenta perché è stata inclusa l'intestazione (che non è sempre così ovvia come nel caso del vettore). –

1

ogni simbolo dichiarato nella libreria standard C++ fa parte dello spazio dei nomi std. Per utilizzare queste dichiarazioni devi farle riferimento con il suo nome completo. vale a dire std ::.
Come ha risposto MichaelM, dovresti usare std :: vector anziché vector. È possibile, tuttavia, utilizzare i seguenti "utilizzando dichiarazioni":
1. using std::vector;
2. using namespace std; // using namespace ...; is mostly discouraged as it causes a mass-import of symbols into the global namespace

In ogni caso, la maggior parte del tempo si dovrebbe evitare l'uso di dichiarazione nei file di intestazione in quanto inquina il namespace globale per ogni utente della tua intestazione.

buona fortuna

Problemi correlati