简体   繁体   中英

Dynamic array of template objects in C++

#include <vector>

using namespace std;

int main()
{
    vector<int> *list = new vector<int>[33];
    delete[] list;
    return 0;
}

Any reason why the delete SIGSEGVs?

It doesn't matter if the type is a template or not. The compiler will expand the code to a normal type. Deleting an array created with new[] you always use delete[] .

The code you pasted is a little unusual but technically valid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM