首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

为什么不能delete?该怎么解决

2012-03-13 
为什么不能delete?char*fun(){char*pnewchar(10)strcpy(p,test )returnp}voidmain(){char*qpfun()

为什么不能delete?
char   *fun()
{
        char   *p   =   new   char(10);
        strcpy(p,   "test ");
        return   p;
}

void   main()
{
        char   *qp   =   fun();
        cout   < <   qp;
        delete   qp;        
}
代码如上,为什么qp不能delete不是说有new就要有delete吗?

[解决办法]
new char(10);=> new char[10];

delete [] qg;
[解决办法]
中括号 new char[10]
不是()
[解决办法]
ls正解

热点排行