2009-10-12 2 views
11

제목에 언급 된 것처럼 왜이 오류가 발생하는지 잘 모르겠습니다. 나는이 구조와 비슷한 test.cpp를한데 모아 두었다. 또한 벡터 문제 이외에도 '보호 된'것에 대한 다른 문제가 있습니다. 이는 코드에도 없습니다. 나는 '보호 된'매크로라고 생각하는데, 거기에는 무엇이 있는지 알려주지 않습니다. 나는 QT를 처음 사용하기 때문에 "잘못하고있다"고 생각합니다. 확실히 컴파일러가 제안하는 것입니다.오류 도움말 : ISO C++에서 형식이없는 '벡터'선언을 금지합니다.

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. 

다음은 코드입니다. 나는 그 오류에서 언급 된 줄에 번호를 매겼다.

#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 

답변

31

벡터는 std 네임 스페이스에 있습니다. 당신이 중 하나를 수행해야 다음

앞에 추가 네임 스페이스와 유형 :

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

당신은 표준 네임 스페이스에서 벡터를 사용하는 컴파일러에게

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

또는 컴파일러에게 모든것을 가져올 std 네임 스페이스를 사용하고 있습니다 (권장하지 않음, 의견보기 참조)

using namespace std; 
+20

인류애를 위해서 헤더 파일에 "네임 스페이스 XXX 사용"을 사용하지 마십시오. 당신은 그것을 가로막는 모든 다른 프로그래머를 울게 만들 것이다. –

+1

동의하지만 사람들에게 옵션을 알려주는 경우도 있습니다) – MichaelM

+1

다음은이 옵션을 포함하는 것입니다 : std :: vector; 나는 .cpp에서 include 다음에 선호한다. 묶는 std :: 모든 곳에서 * 및 * 헤더가 포함 된 이유 (벡터의 경우처럼 항상 명확하지는 않음)를 저장합니다. –

1

C++ 표준 라이브러리에서 선언 된 모든 기호는 std 네임 스페이스의 일부입니다. 이러한 선언문을 사용하려면 전체 이름으로 참조해야합니다. 즉 std ::.
MichaelM이 대답 했으므로 vector 대신 std :: vector를 사용해야합니다. 당신은, 그러나, 다음 "을 사용하여 선언"를 사용할 수 있습니다 : 그것은 글로벌 네임 스페이스를 오염으로 어떤 경우에
1. using std::vector;

을, 대부분의 시간을 당신은 헤더 파일에 선언을 사용하지 않아야합니다 헤더의 모든 사용자에 대해

행운을 빕니다

관련 문제