how many layer the vector can be?

K

kathy

I try to use:

std::vector <std::vector <std::vector <int>>>;

But it seems not work.

how many layer the vector can be?

for example:

std::vector <std::vector <std::vector <int>>> v1;
std::vector <std::vector <int>> v2;

v1.resize(2);
v1[0].resize(2);
v1[0][0].resize(2);
v1[0][0][0] = 1;//wrong

v2.resize(2);
v2[0].resize(2);
v2[0][0] = 1;//OK
 
A

acehreli

I try to use:

std::vector <std::vector <std::vector <int>>>;

You need to put spaces between > characters. Otherwise the compiler
parser will take two of them together to be the right shift operator:
Better yet, use typedefs to make this code more readable:

typedef vector<int> SomeType;
typedef vector<SomeType> SomeName;
typedef vector<SomeName> SomeOtherName;

Ali
 
J

Joe Greer

I try to use:

std::vector <std::vector <std::vector <int>>>;

But it seems not work.

how many layer the vector can be?

I am sure there is some compiler limit, but mostly it will depend upon how
many you enter in your declaration.
for example:

std::vector <std::vector <std::vector <int>>> v1;

std::vector <std::vector <int>> v2;

v1.resize(2);
v1[0].resize(2);
v1[0][0].resize(2);
v1[0][0][0] = 1;//wrong

v1 is a vector of vectors of vectors of int
v1[0] is a vector of vectors of int
v1[0][0] is a vector of int
v1[0][0][0] is not valid.

hope that helps,
joe
 
R

red floyd

Joe said:
I try to use:

std::vector <std::vector <std::vector <int>>>;

But it seems not work.

how many layer the vector can be?

I am sure there is some compiler limit, but mostly it will depend upon how
many you enter in your declaration.
for example:

std::vector <std::vector <std::vector <int>>> v1;

std::vector <std::vector <int>> v2;

v1.resize(2);
v1[0].resize(2);
v1[0][0].resize(2);
v1[0][0][0] = 1;//wrong

v1 is a vector of vectors of vectors of int
v1[0] is a vector of vectors of int
v1[0][0] is a vector of int
v1[0][0][0] is not valid.

v1[0][0][0] is a reference to an int.
 
K

kathy

v1 is a vector of vectors of vectors of int
v1[0] is a vector of vectors of int
v1[0][0] is a vector of int
v1[0][0][0] is not valid.

hope that helps,
joe

I believe the v1[0][0][0] IS valid. It is integer.
 
J

Joe Greer

Joe said:
I try to use:

std::vector <std::vector <std::vector <int>>>;

But it seems not work.

how many layer the vector can be?

I am sure there is some compiler limit, but mostly it will depend
upon how many you enter in your declaration.
for example:

std::vector <std::vector <std::vector <int>>> v1;

std::vector <std::vector <int>> v2;

v1.resize(2);
v1[0].resize(2);
v1[0][0].resize(2);
v1[0][0][0] = 1;//wrong

v1 is a vector of vectors of vectors of int
v1[0] is a vector of vectors of int
v1[0][0] is a vector of int
v1[0][0][0] is not valid.

v1[0][0][0] is a reference to an int.

True, my bad. sigh.

joe
 
J

James Kanze

kathy wrote:

[...]
Many. The limitation should be documented in your compiler
manual.

From a quality of implementation point of view, probably, but
I'm not sure that the standard requires that the implementation
limits be documented. In practice, the most I think you'll find
is how deep templates can be nested. And since you don't know
how deep the implementation of std::vector nests them already,
that doesn't advance you much.

If the error is due to template nesting, some compilers have
options to increase it. (Early implementations of templates
often made it artificially low, since the typical case was
unintentional recursion, without a specialization to stop it. I
think that these restrictions are being raised, because the only
way to implement a loop in template metaprogramming is via such
recursion.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top