Re: Work with Arrays
On Apr 30, 9:56 am, Frank Liebelt <ecos...@hotmail.com> wrote:
Hi
Hi Frank,
I hope my english ist good enough to explain what my problem is.
I hope mine is good enough to answer :-)
I want to create a array with two dimensions. Each index should have a
second dimension with three indexes.
Like: myarr[0][0-2] , myarr[1][0-2] and so on...
The size of the first dimension is unknown the second ist allways three.
[snip]
Within the headerfile i wrote: vector<char> arrSpec;
[snip]
Now the Problem.
-> arrSpec[listPos].resize(3);
Wont work. I got the following compiler error:
The return type of operator[] is the vector's element type which is,
in the present case, "char". "char" does not have a "resize" member
function.
The next three line have this compiler error:
invalid types `char[int]' for array subscript
And "char" has no operator[] either.
What you're trying to achieve is not entirely clear to me, but do you
really need to access the sub-elements with this double indexing
scheme? Looking at your code below, it seems that sub-index 0 is
always "id", 1 is "name" and 2 is "path". So, for example, to get the
name of the n-th element, would'nt this:
arrSpec[n].name
be more expressive than:
arrSpec[n][1]
?
If yes, then a solution could be: create a type for your elements,
say:
struct Element
{
char* id;
char* name;
char* path;
};
and store you data in a vector<Element>
If you really need to use a double-indexing scheme, you could use
boost::array, and define your vector as:
std::vector<boost::array<char*, 3> >
HTH,
=C9ric Malenfant