abraxas334
April 27th, 2009, 10:02 AM
Hi,
this is probably a very silly question coming from an unexperience programmer.
so i have a class and within that class i have defined a vector like this:
vector<int>Array;
now i want to init the vector in the constructor so it has a certain size and the entries are set to a certain value.
if i was doing this in main or any function if i define a vector i can do it like this:
vector<int>Array(10,0) // has 10 entries with value zero
Is there a syntax like that for initing a vector if it has already been definied as a private variable in a class. Or is this the the only way of giving the vector a size of 10 with values 0 in the constructor of the class
for(int i =0; i<10; i++)
{
Array.push_back(0);
}
i mean this method works fine I was just wondering if there was an alternative.
Thanks a lot
this is probably a very silly question coming from an unexperience programmer.
so i have a class and within that class i have defined a vector like this:
vector<int>Array;
now i want to init the vector in the constructor so it has a certain size and the entries are set to a certain value.
if i was doing this in main or any function if i define a vector i can do it like this:
vector<int>Array(10,0) // has 10 entries with value zero
Is there a syntax like that for initing a vector if it has already been definied as a private variable in a class. Or is this the the only way of giving the vector a size of 10 with values 0 in the constructor of the class
for(int i =0; i<10; i++)
{
Array.push_back(0);
}
i mean this method works fine I was just wondering if there was an alternative.
Thanks a lot