My code is the following:
#include <vector>
int main() {
std::vector<int> *vec;
vec->push_back(1);
return 0;
}
This program segfaults, no matter which compiler I try it with. I also tried using a smart pointer, but it also segfaults. I now have two questions:
- Why and how can I solve this?
- Does having a pointer to a
vector(specifically a smart pointer) even make sense? In my online searches, I only saw it the other way around, avectorofunique_ptr's. Which makes more sense and why?