473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

constructing nested vectors

If I have the following class member:

std::vector<floatsingleVector;

I can initialize it to have 50 elements with values of 0.5:

singleVector = std::vector<float>( 50, 0.5 );

My question concerns when I move to using this class member:

std::vector<std::vector<float>nestedVector;

and attempt to initialize:

nestedVector = std::vector<std::vector<float>>( 50,
std::vector<float>( 10, 0.5 ) );

which I would expect would initialize the vector to have 50 nested
vectors, each having 10 elements with values of 0.5.

This does not, however, compile.

Anjo

Jul 24 '07 #1
1 2349

Anjo Gasa <an******@gmail.comwrote in message...
If I have the following class member:
std::vector<floatsingleVector;
I can initialize it to have 50 elements with values of 0.5:
singleVector = std::vector<float>( 50, 0.5 );
My question concerns when I move to using this class member:
std::vector<std::vector<float>nestedVector;
and attempt to initialize:
nestedVector = std::vector<std::vector<float>>( 50,
std::vector<float>( 10, 0.5 ) );
which I would expect would initialize the vector to have 50 nested
vectors, each having 10 elements with values of 0.5.
This does not, however, compile.
Anjo
If possible, do it all in one shot:

std::vector<std::vector<float nestedVector( 50,
std::vector<float>( 10, 0.5 ) );

Note what Alf said about the 'space':

// .....float>// no space, no good
.....float // that's '>' + ' ' + '>'

Otherwise it's taken as a 'right-shift'(7 >2) or 'insertion'(cin >>
intvar) operator, and the compiler has a heart attack because it can't
figure out what you are trying to shift/insert from-to.

--
Bob R
POVrookie
Jul 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pratyush | last post by:
Hi, Suppose there is a vector of objects of class A, i.e., std::vector<A> vec_A(N); The class A satisifies all the STL vector requirements. Now I wish to add some attributes for each of the...
5
by: Computer Whizz | last post by:
I was reading through Accelerated C++ at work when I read through the first mention of Vectors, giving us certain functions etc. Is there any benefit of Arrays over Vectors? Since all Vectors...
3
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
37
by: Tim N. van der Leeuw | last post by:
Hi, The following might be documented somewhere, but it hit me unexpectedly and I couldn't exactly find this in the manual either. Problem is, that I cannot use augmented assignment operators...
9
by: Bill Grigg | last post by:
All, Can anyone supply an example or reference to an example of using reflection to determine the data types and array lengths contained in a nested stucture in C#? Actually, it is a structure...
5
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
1
by: nabil | last post by:
Hi I have probleam while while initilazing nested class ... I needs to create a object 'b' of B(nested class) in A(surrounding class). while constructing b I have to pass pointer of funtion...
18
by: desktop | last post by:
I have 3 types of objects: bob1, bob2 and bob3. Each object is identified by a unique ID which gets returned by the function getId(). All bobs are descendants from class BaseBob which is an...
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.