[英]Help with error: ISO C++ forbids declaration of 'vector' with no type
正如标题所述,我不确定为什么我会收到此错误。 我已经整理了一个类似于这个结构的test.cpp,它运行正常。 另外,除了向量问题之外,还有另一个关于'protected'的问题,即使在代码中也是如此。 我认为'protected'是一个宏,所以不知道那里有什么。 我是QT的新手,所以我很可能“做错了。” 这肯定是编译器的建议。
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
Vector驻留在std命名空间中。 您必须执行以下操作之一:
在命名空间前面添加类型:
std::vector<std::vector<char *> > chars;
告诉编译器您正在使用std命名空间中的vector
using std::vector;
vector<vector<char *> > chars;
或者,告诉编译器您正在使用std命名空间,这将引入所有内容(不推荐,请参阅注释)
using namespace std;
在C ++标准库中声明的每个符号都是std命名空间的一部分。 要使用这些声明,您必须使用其全名来引用它。 即std ::。
正如MichaelM回答的那样,你应该使用std :: vector而不是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
using namespace std; // using namespace ...; is mostly discouraged as it causes a mass-import of symbols into the global namespace
在任何情况下,大多数情况下,您应该避免在头文件中使用声明,因为它会污染标头的每个用户的全局命名空间。
祝好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.