tags:

views:

2455

answers:

2

As the title states, I'm not sure why I'm getting this error. I've put together a test.cpp that's similar to this structure, and it works fine. Also, other than the vector problem, there's the other problem about 'protected', which isn't even in the code. I think 'protected' is a macro, so no telling what's there. I'm new to QT, so I'm likely "doing it wrong." That's certainly what the compiler's suggesting.

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.

Here's the code. I've numbered the lines noted in the error.

#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
+15  A: 

Vector resides in the std namespace. You have to do one of the following:

Prepend the type with the namespace:

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

Tell the compiler you are using vector from the std namespace

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

Or, tell the compiler you are using the std namespace, which will bring in everything (not recommended, see comments)

using namespace std;
MichaelM
Please, for the love of humanity, don't "using namespace XXX" in a header file. You'll make every other programmer who comes across it cry.
Caleb Huitt - cjhuitt
Agreed, but you may as well tell people the options ;)
MichaelM
Well then include this option: using std::vector; I prefer it in the .cpp immediately after the include. Saves tying std:: all over the place *and* documents why the header was included (which is not always as obvious as in the case of vector).
Steve Fallows
good point, have edited my answer
MichaelM
@cjhuitt - Cry? I won't cry - at least not until I've hunted him down...
Steve314
c'mon - it's not that bad. **IF** you put it **inside** your class definition. Like any declaration it's scoped.
MSalters
+1  A: 

every symbol declared in C++ standard library is part of the std namespace. In order to use these declarations you have to refer it by its full name. namely std::.
As MichaelM answered you should use std::vector instead of vector. You can, however, use the following "using declarations":
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

On any case, most of the time you should avoid using declaration in header files as it pollutes the global namespace for every user of your header.

good luck

Oren S