Click here to Skip to main content
15,611,482 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sorry for my question,but I'm getting confused with a simple things.

define type Vector<int> VecIdx,

(VecIdx & Vector) Is a vector of vector or a vector of vector of vector. I know my question is a naive question,sorry for that.

What I have tried:

Define type     Vector<int>    VecIdx,

(VecIdx & Vector) <pre>
Updated 15-Jul-21 10:36am
jeron1 15-Jul-21 11:10am    
Richard MacCutchan 15-Jul-21 12:02pm    
"(VecIdx & Vector) Is a vector of vector or a vector of vector of vector."
No, because none of what you have posted is valid C++ code.
Member 15181211 15-Jul-21 13:46pm    
I defined a header file which contains data like this
Typedef std::vector<size_t> VecIdx_t.
So wherever I want to define a vector of type size_t I use VecIdx_t.
My question somehow deals with vector of vector and vector of vector of vector. For example if I have a triple vector. I don't know how to access each vector if I have a vector of vector of vector
Richard MacCutchan 16-Jul-21 3:09am    
That does not really explain what problem you are trying to solve; perhaps if you showed some code is would help. But creating a vector of vectors is a simple matter:
std::vector<std:vector<int>> vec1; // is a vector of vectors
std::vector<std:vector<std:vector<int>>> vec2; // is a vector of vectors of vectors

Writing complex code is often a result of not understanding the language or the to solving problem.

So you better be read and understand the vector reference to be really sure you are understand using the class. Like hammering with a pliers is more a "bush fix" than a good idea for a craftsman. ;-)

PS: my experience is that learning the basics is always well spend time, because it prevents you making wrong decisions.
Share this answer
I am a fan of the using and typedef statements. They are pretty close to the same thing for this purpose although the using statement has quite a bit more capability.

For this you can add some statements to define the types in layers. Let's say you want a vector of vectors of vectors of data. Here's how that might look.
using vdata   = std::vector< data >;
using vvdata  = std::vector< vdata >;   // a vector of vectors
using vvvdata = std::vector< vvdata >;  // a vector of vectors of vectors

// one instance of it :

vvvvdata MyVector;
The equivalent typedef statement for the first using statement there is :
typedef std::vector< data >  vdata;
As you can see, they are essentially backwards from each other and typedef does not use an equals sign.
Share this answer
CPallini 16-Jul-21 2:11am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900