Create and delete
You can construct each container by a multitude of constructors. To delete all elements of a container cont
, you can use cont.clear()
. It makes no difference if you create a container, if you delete them or if you add or remove elements. Each time the container takes care of the memory management.
The table shows you the constructors and destructors of a container. A std:vector
stands for the rest of them.
Type | Example |
---|---|
Default | std::vector<int> vec1 |
Range | std::vector<int> vec2(vec1.begin(), vec1.end()) |
Copy | std::vector<int> vec3(vec2) |
Copy | std::vector<int> vec3= vec2 |
Move | std::vector<int> vec4(std::move(vec3)) |
Move | std::vector<int> vec4= std::move(vec3) |
Sequence (Initializer list) | ...