当前位置: 动力学知识库 > 问答 > 编程问答 >

C++ core dump in Linux when using string as template type

问题描述:

This simple piece of code causes a core dump. I'm using gcc 4.8.2 in Linux.

template <class T>

class X

{

T c;

};

int main(int argc, char **argv)

{

X<string> *x = new X<string>[7];

delete x;

return 0;

}

I appreciate any help, I'm really confused with this. It doesn't cause a core dump when I use int instead of string.

网友答案:

You called new [] so you need to call delete []:

delete [] x;
分享给朋友:
您可能感兴趣的文章:
随机阅读: