1. Vector Nesting

Hello

Is there a function (call it nest for this example) that nests vectors?

Like this

Code:
```nest("char",3); //Result: vector< vector< vector<char> > >
nest("string",2); //Result: vector< vector<string> >
nest("int",4); //Result: vector< vector< vector< vector<int> > > >```
nest(string type, int amount)
Or a method like it?

Thanks

2. No... functions do not return variable types (c++ is static typed)

Do you even know what you want to achieve with this?

#define NEST_2(container, type) container< container< type > >
#define NEST_3(container, type) container< container< container < type > > >

#define NEST_VECTOR_2(type) NEST_2(vector, type)

etc.

3. Originally Posted by kmdv
Do you even know what you want to achieve with this?
Yes, you should consider the above question. Boost.Multi-Array may have been mentioned to you before, but if not, you should take a look and see if it meets your requirements.

4. Is it possible to have jagged arrays using normal arrays?
Something like

Code:
```int i[2]; //makes i[0] and i[1]
i[0] = new int[2]; //makes i[0][0], i[0][1]
i[1] = new int[3]; //makes i[1][0],i[1][1],i[1][2]

i[0][0] = 0;
i[0][1] = 1;

i[1][0] = 2;
i[1][1] = 3;
i[1][2] = 4;```

Thanks guys

5. You use new on pointers, not arrays.
Code:
```int* array[2];
array[0] = new int[5];
array[1] = new int[10];```

6. Is it possible to do something like this

Code:
```    string* str[2]; //allows str[0] & str[1]
str[0] = new string * [2]; //allows str[0][0] & str[0][1]
str[1] = new string * [3]; //allows str[1][0] & str[1][1] & str[1][2]
str[0][0] = "0,0";
str[0][1] = "0,1";
str[1][0] = "1,0";
str[1][1] = "1,1";
str[1][2] = "1,2";```
Thanks

7. You can use new as many times as there are stars in your variable definition.

It's an array of string pointers.

string *str[2];
str[0] = new string ("0,0");
str[1] = new string ("0,1");

8. Oh okay. I tried with 2 stars but it doesn't compile for some reason.

Code:
```    string** a[2]; //visually : { a[0] , a[1] }
a[0] = new string[2]; //visually : { {a[0][0],a[0][1]} , a[1] }
a[1] = new new string[2]; // visually : { {a[0][0],a[0][1]} , {{a[1][0][0],a[1][0][1]}} }

a[0][0] = "0,0"; cout << a[0][0] << endl;
a[0][1] = "0,1"; cout << a[0][1] << endl;
a[1][0][0] = "1,0,0"; cout << a[1][0][0] << endl;
a[1][0][1] = "1,0,1"; cout << a[1][0][1] << endl;```
If the vector is visualized, I'm going for
{ {a[0][0], a[0][1]} , {{a[1][0][0], a[1][0][1]}} }

Errors:

cannot convert `std::string*' to `std::string**' in assignment
expected identifier before "new"
expected `;' before "new"
cannot convert `const char[4]' to `std::string*' in assignment

Thanks

9. Unless you know the number of strings you want, setting up a normal array doesn't make sense. You new[] yourself some string pointers (to serve as an array-like structure) and then new strings for yourself. As I said before you can use new as many times as there are stars in the definition... The result: you should have a matrix str[x][y].

10. Have you checked out Boost.Multiarray? You are doing stuff unnecessarily complicated and shooting yourself in the foot by trying to reach the stars.