-
In C++ we have value type (int, long, float, …) and reference type (class, struct, …).
-
For value type, Array and Vector hold the actual values;
-
For reference type, Array and Vector only hold the references to these objects;
-
So when we put reference type into Array and Vector, we need to make sure those objects will exist long enough (valid during the entire process) to avoid exception/error;
My above statements are correct or not? please correct me if I am wrong.
No. Any type can be passed by value or by reference (also any type can be created on the stack or on the heap, though you didn’t ask that).
For any type Arrays and Vectors hold the actual values. Because of this any type stored in a vector needs to be copy-constructible.
See 2.
Nope. That’s only the case if you explicitly create a vector of pointers and then store a pointer to your object.