Kurt,
You should rather use std::vector<vtkSmartPointer>> v;
and then set your vector:
v.resize(size)
forall i:
v[i] = vtkSmartPointer ::New();
or you can use
push_back as you showed.
This way the pointers will be deallocated when the vector goes out of scope.
I see. In that case I don’t have a better solution than just adding the pointers to vktDataArray. You have to make sure the vtkSmartPointer<…> don’t go out of scope before your vector,
otherwise your pointers stored in vector elements will become invalid.
std::vector<vtkSmartPointer<vtkDataArray>> vec;
auto arr = vtkSmartPointer<vtkFloatArray>::New();
// or
vtkNew<vtkFloatArray> arr;
/* do stuff with arr */
vec.push_back(arr);
// or vec.push_back(std::move(arr)); if you're done with arr and want
// to avoid touching the reference count unnecessarily.
It’s better to use smart pointers in the vector so that you don’t have to worry about the lifetimes of raw vtkDataArray* pointers. The smart pointers have optimized move operations so you won’t have to worry about expensive ref count updates when the vector dynamically resizes.