I’ve defined a vector in my program as follows:
vector<bool> isPrime (limit + 1, false);
where limit is an int. Later on in the program, I want to recycle the vector, keeping the name but reducing the size and populating all elements with false.
I’ve tried using
vector<bool> isPrime (otherLimit + 1, false);
in the same way one would redefine an int, char or string, but that returns an error, and since I didn’t instantiate it with the new operator, I can’t delete the old one. I’ve been able to manually resize it and and convert each element to false using a for loop, but that seems rather clunky to me.
Is there an easier way to recycle a vector? My desire is to keep the name the same throughout for readability purposes.
You could either
or use it’s members
clearandresize: