jaens
jaens

Reputation: 1

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?

Upvotes: 0

Views: 1366

Answers (1)

Brian R. Bondy
Brian R. Bondy

Reputation: 347216

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.

Upvotes: 4

Related Questions