You can use the resize function.
This will set the size to 1 and initialize the one new elements to 0.
If you want to explicitly specify which value you want to give to the new elements you can pass the value as a second argument.
If you just want to add an element to the end of the vector the simplest is usually to use push_back.
This adds a new element with value 0 to the end of the vector.
Since you know the size when you create the vector you might want to construct the vector with that size.
You can do this using the member initializer list.
1 2 3 4
|
BigUnisigedInt()
: vector(1)
{
}
|
This works the same as resize. You can pass a second argument if you want the element's initial value to be something other than 0.
You can also use the brace-initialization syntax.
1 2 3 4
|
BigUnisigedInt()
: vector{0}
{
}
|
If you want the vector to have more elements you can just list them between { } with commas in between (e.g. vector{0, 1, 8} creates a vector with three elements having the values 0, 1 and 8).
It is also possible to use this kind of initialization directly when defining the member variable.
|
std::vector<int> vector{0};
|
This might be suitable if you always want the vector to have at least one element. If you add more constructors you don't need to repeat the same initialization in each of them.