wchar_t *删除 [英] wchar_t * delete

查看:109
本文介绍了wchar_t *删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试删除temp1时,它会给出运行时错误


wchar_t * temp1 = L" Test1";

delete [] temp1;


如何删除temp1

When I try to delete the temp1 it gives a run time error

wchar_t *temp1 = L"Test1";
delete[] temp1;

how do I delete temp1

推荐答案


当我尝试删除它给出运行时错误的temp1


wchar_t * temp1 = L" Test1";

delete [] temp1;

如何删除temp1
When I try to delete the temp1 it gives a run time error

wchar_t *temp1 = L"Test1";
delete[] temp1;

how do I delete temp1



你不是因为你没有分配任何记忆;那个temp1指针指向

到一个不能写入的文字字符串,也不能删除它。


亲切的问候,


Jos

You don''t because you haven''t allocated any memory; that temp1 pointer points
to a literal string that can''t be written to nor can it be deleted.

kind regards,

Jos


Ok


我也将此字符串传递给类中的函数


LineText :: LineText(wchar_t * message)

{

sDisplayText = message;

}


所有这些都可以解决任何问题,如果我不删除sDisplayText使用delete [] sDisplayText


我现在很困惑。如果它可以作为指针被传递到它被销毁的时候?
Ok

I am also passing this string to a function in a class

LineText::LineText(wchar_t* message)
{
sDisplayText = message;
}

All of them work with out any problem, if I don?t delete sDisplayText using delete[]sDisplayText

I am confused now. If it can be passed to a function as pointer when does it get destroyed?


确定


我也将这个字符串传递给一个函数一个班级


LineText :: LineText(wchar_t * message)

{

sDisplayText = message;

}


如果我不在类的析构函数中使用delete [] sDisplayText删除sDisplayText,它们都可以解决任何问题。

我现在很困惑。如果可以将它作为指针传递给它什么时候被销毁?


如果它可以被传递,它是否会以某种方式结束直到程序结束?
Ok

I am also passing this string to a function in a class

LineText::LineText(wchar_t* message)
{
sDisplayText = message;
}

All of them work with out any problem, if I don?t delete sDisplayText using delete[]sDisplayText in the destructor of the class.

I am confused now. If it can be passed to a function as pointer when does it get destroyed?

If it can be passed around does it remain somehow until the program ends?


这篇关于wchar_t *删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆