A
A
There are 2 vectors each one having a structure
struct MyStruct
{
int a;
std::string b;
}
std::vector<MyStruct> v1;
std::vector<MyStruct> v2;
Now I want a pointer to which one I will use... v1 or v2
std::vector<MyStruct> *v = (condition)? &v1 : &v2;
Finally I access it using:
for (unsigned i = 0; i < v->size(); i++)
{
v->operator[](i).a = i + 1;
}
My lack of understanding here is:
a) does the above *v needs to be deleted? Isn't it just a pointer variable?
Or it works differently when it points to a vector? Just to be clear, I
don't actually need to delete v1 or v2. I just need to cleanup *v if
required.
b) what's the heap or stack or difference or advantage of them in relation
to the above?
struct MyStruct
{
int a;
std::string b;
}
std::vector<MyStruct> v1;
std::vector<MyStruct> v2;
Now I want a pointer to which one I will use... v1 or v2
std::vector<MyStruct> *v = (condition)? &v1 : &v2;
Finally I access it using:
for (unsigned i = 0; i < v->size(); i++)
{
v->operator[](i).a = i + 1;
}
My lack of understanding here is:
a) does the above *v needs to be deleted? Isn't it just a pointer variable?
Or it works differently when it points to a vector? Just to be clear, I
don't actually need to delete v1 or v2. I just need to cleanup *v if
required.
b) what's the heap or stack or difference or advantage of them in relation
to the above?