2009-10-12 22 views
11

के साथ 'वेक्टर' की घोषणा को रोकता है शीर्षक के अनुसार, मुझे यकीन नहीं है कि मुझे यह त्रुटि क्यों मिल रही है। मैंने एक test.cpp को एक साथ रखा है जो इस संरचना के समान है, और यह ठीक काम करता है। इसके अलावा, वेक्टर समस्या के अलावा, 'संरक्षित' के बारे में दूसरी समस्या है, जो कोड में भी नहीं है। मुझे लगता है कि 'संरक्षित' एक मैक्रो है, इसलिए कोई बात नहीं है कि वहां क्या है। मैं क्यूटी के लिए नया हूं, इसलिए मुझे लगता है कि "यह गलत कर रहा है।" निश्चित रूप से संकलक का सुझाव क्या है।त्रुटि के साथ सहायता: आईएसओ सी ++ किसी भी प्रकार

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 में पसंद करता हूं। Std :: सभी जगह * और * दस्तावेज़ों को बांधने से बचाता है क्यों हेडर शामिल किया गया था (जो वेक्टर के मामले में हमेशा स्पष्ट नहीं है)। –

1

सी ++ मानक पुस्तकालय में घोषित हर प्रतीक std नेमस्पेस का हिस्सा है। इन घोषणाओं का उपयोग करने के लिए आपको इसे अपने पूर्ण नाम से संदर्भित करना होगा। अर्थात् std ::।
जैसा कि माइकलएम ने उत्तर दिया है कि आपको वेक्टर के बजाय std :: vector का उपयोग करना चाहिए। हालांकि, आप निम्नलिखित "घोषणाओं का उपयोग कर" का उपयोग कर सकते हैं:
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

किसी भी मामले पर, समय की सबसे आप हेडर फाइल में घोषणा का उपयोग कर के रूप में यह ग्लोबल नेम स्पेस को प्रदूषित करने से बचना चाहिए आपके हेडर के प्रत्येक उपयोगकर्ता के लिए।

सौभाग्य

संबंधित मुद्दे