I want to use an array (of size count) of three fields – a long a, an int vector of length 9 named b and a bool c.
What is the right way to declare it?
Declaration 1:
vector <long a, vector<int> b(9), bool c> matrix(count);
Errors:
code.cpp: In function ‘int main()’:
code.cpp:89:49: error: template argument 1 is invalid
code.cpp:89:49: error: template argument 2 is invalid
code.cpp:89:57: error: invalid type in declaration before ‘(’ token
Declaration 2:
vector <long, vector<int>, bool> matrix(count, a, vector<int> b(9), c);
Errors:
code.cpp: In function ‘int main()’:
code.cpp:90:40: error: wrong number of template arguments (3, should be 2)
/usr/include/c++/4.5/bits/stl_vector.h:170:11: error: provided for ‘template<class _Tp, class _Alloc> class std::vector’
code.cpp:90:48: error: invalid type in declaration before ‘(’ token
code.cpp:90:56: error: ‘a’ was not declared in this scope
code.cpp:90:71: error: expected primary-expression before ‘b’
code.cpp:90:77: error: ‘c’ was not declared in this scope
code.cpp:90:78: error: initializer expression list treated as compound expression
I an new to STL and am not sure what is the right syntax here?
STL templates, usually, take only one parameter determining a type of contained data (and there is always a fixed number of parameters).
To get the expected effect you have to create a structure
and create a vector of objects of type
s;In order to initialize objects contained in a structure you have iterate over a vector and assign them manually, or declare a default contructor.