Is it correct to declear a vector like below? In document, it says ok, but when compiling it, it gives error. If I remove (200), then compiling ok.
QVector<QString> vector(200);
Is it correct to declear a vector like below? In document, it says ok, but when compiling it, it gives error. If I remove (200), then compiling ok.
QVector<QString> vector(200);
Edit:
Wrong stuff said.
Last edited by high_flyer; 1st February 2011 at 13:35.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
thanks for the reply, but both of your examples compiling failed also. (declaration syntax error)
funny enough, this is copied from qt doc
http://doc.qt.nokia.com/latest/qvector.html#details
any ideas?
You original code is correct.
Post you code, the problem is probably somewhere else.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
if you copy that line to any header file, and then compile, you will see the compiling error!
This:
is just fine for me.Qt Code:
#include <QString> #include <QVector> QVector<QString> vector(200); int main(int argc, char **argv) { }To copy to clipboard, switch view to plain text mode
Exactly what is the error message when you compile that?
Hi,
As I said, put it to a class header file for example, then it will give "declaration syntax error". What I want is to define a fix sized vector contains constant strings or other struct.
#include <QString>
#include <QVector>
class MyClass
{
...
private:
QVector<QString> vector(200);
};
Thanks,
Last edited by zhxys; 2nd February 2011 at 08:47.
Ah, of course, you can't intialize like that in a header!
In you header you do:
And in the implementation then you do:
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
zhxys (3rd February 2011)
Or, a slight variation using the initialisation list:
Qt Code:
// test.h class Test { QVector<QString> vector; public: Test(); }; // test.cpp Test::Test(): vector(200) { }To copy to clipboard, switch view to plain text mode
zhxys (3rd February 2011)
Bookmarks