Can I force std::vector to not deallocate its memory after the vector goes out of scope?
For example, if I have
Not sure but, yes.
You can create a custum allocator who do nothing when deallocate => leak
Or may be you can jsut create your vector
on the heap so it will leak anyway.
int* foo() {
std::vector* v = new std::vector(10,1);
return &((*v)[0]);
// no delete
}
int main()
{
int* bar = foo();
std::cout << bar[5] << std::endl;
}