Assuming an implementation which actually has a stack and a heap (standard C++ makes no requirement to have such things) the only true statement is the last one.
vector<Type> vect;
//allocates vect on stack and each of the Type (using std::allocator) also will be on the stack
This is true, except for the last part (Type
won't be on the stack). Imagine:
void foo(vector<Type>& vec) {
// Can't be on stack - how would the stack "expand"
// to make the extra space required between main and foo?
vec.push_back(Type());
}
int main() {
vector<Type> bar;
foo(bar);
}
Likewise:
vector<Type> *vect = new vector<Type>; //allocates vect on heap and each of the Type will be allocated on stack
True except the last part, with a similar counter example:
void foo(vector<Type> *vec) {
// Can't be on stack - how would the stack "expand"
// to make the extra space required between main and foo?
vec->push_back(Type());
}
int main() {
vector<Type> *bar = new vector<Type>;
foo(bar);
}
For:
vector<Type*> vect; //vect will be on stack and Type* will be on heap.
this is true, but note here that the Type*
pointers will be on the heap, but the Type
instances they point to need not be:
int main() {
vector<Type*> bar;
Type foo;
bar.push_back(&foo);
}