panJames
asked on
std::vector<std::vector<int>> linesGrid(64, std::vector<int>(48));
Hello experts,
std::vector<std::vector<in t>> linesGrid(64, std::vector<int>(48));
Trying to have a good understanding of this line of code so opened a new question for it.
I am looking at cplusplus.com and do not really get a good grip of this problem.
Here are constructors:
1. explicit vector ( const Allocator& = Allocator() );
2. explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() );
3. template <class InputIterator>
vector ( InputIterator first, InputIterator last, const Allocator& = Allocator() );
4. vector ( const vector<T,Allocator>& x );
Now I try to understand these constructors.
ad 1. Let's start with the first one (once I get this one, it should help with the others!)
"const Allocator& = Allocator()"
What does it mean?
Thank you
panJames
std::vector<std::vector<in
Trying to have a good understanding of this line of code so opened a new question for it.
I am looking at cplusplus.com and do not really get a good grip of this problem.
Here are constructors:
1. explicit vector ( const Allocator& = Allocator() );
2. explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() );
3. template <class InputIterator>
vector ( InputIterator first, InputIterator last, const Allocator& = Allocator() );
4. vector ( const vector<T,Allocator>& x );
Now I try to understand these constructors.
ad 1. Let's start with the first one (once I get this one, it should help with the others!)
"const Allocator& = Allocator()"
What does it mean?
Thank you
panJames
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
This question seems to be about understanding that line of code, not about finding alternative ways of doing it ...
If you have a good debugger (such as VS 2010), then you can step through the program and observe carefully the differences in how matrix1 and matrix2 are constructed and filled.
ASKER
std::vector<std::vector<in t>> linesGrid(64, std::vector<int>(48));
explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() );
>> how do you translate this constructor into our example?
"std::vector<std::vector<i nt>>" is "vector"?
"( size_type n, const T& value= T(), const Allocator& = Allocator() )" is "(64, std::vector<int>(48))" ?
where is "linesGrid" then?
panJames
explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() );
>> how do you translate this constructor into our example?
"std::vector<std::vector<i
"( size_type n, const T& value= T(), const Allocator& = Allocator() )" is "(64, std::vector<int>(48))" ?
where is "linesGrid" then?
panJames
Do you know what constructors are, and how they are used ?
Have a look at this tutorial on using classes in C++ to get a better understanding :
http://www.cplusplus.com/doc/tutorial/classes/
http://www.cplusplus.com/doc/tutorial/classes2/
In something like :
Type object(argument1, argument2);
Type is the type of the object we want to create, object is the actual instance we create, and argument1 and argument2 are the arguments that are passed to the constructor.
Have a look at this tutorial on using classes in C++ to get a better understanding :
http://www.cplusplus.com/doc/tutorial/classes/
http://www.cplusplus.com/doc/tutorial/classes2/
In something like :
Type object(argument1, argument2);
Type is the type of the object we want to create, object is the actual instance we create, and argument1 and argument2 are the arguments that are passed to the constructor.
ASKER
<Infinity08>
In something like :
Type object(argument1, argument2);
Type is the type of the object we want to create, object is the actual instance we create, and argument1 and argument2 are the arguments that are passed to the constructor."
</Infinity08>
Somehow I thought that:
Type object(argument1, argument2);
object needs to have the same name as class to "work" as constructor.
panJames
In something like :
Type object(argument1, argument2);
Type is the type of the object we want to create, object is the actual instance we create, and argument1 and argument2 are the arguments that are passed to the constructor."
</Infinity08>
Somehow I thought that:
Type object(argument1, argument2);
object needs to have the same name as class to "work" as constructor.
panJames
>> object needs to have the same name as class to "work" as constructor.
No. The class is mentioned in Type already.
No. The class is mentioned in Type already.