Where does a std::vector allocate its memory?

后端 未结 4 1977
生来不讨喜
生来不讨喜 2020-12-13 13:53

Consider the following code snippet:

#include 
using namespace std;

void sub(vector& vec) {
    vec.push_back(5);
}

int main()         


        
4条回答
  •  情深已故
    2020-12-13 14:30

    Because you gave sub the adress of the vector in the heap, it will allocate in the heap. If there's no space left, exception should be thrown.

提交回复
热议问题