English 中文(简体)
C++ 删除运营商的混淆[重复]
原标题:C++ delete operator confusion [duplicate]
This question already has answers here:
Closed 12 years ago.

Possible Duplicate:
( POD )freeing memory : is delete[] equal to delete ?

char* pChar = new char[10];

delete pChar; // this should not work but it has same effect as 
              // delete[], WHY?
              // I know this is illegal, but why does it work?
问题回答

它可以appear产生同样的效果,但效果并非如此。 如果贵国的阵列类型是抽象的数据类型(即一个类别),那么过去9个要素的主子就不会被称作。

因为你 go。 这是没有界定的行为。 无法界定的行为的一种可能性是,即使确实发生了一些坏事,似乎也不会发生任何坏事。 直到以后,你才可能发现。

你们可以指望得到一些原始类型的安全。 http://isocpp.org/wiki/faq/freestore-mgmt#delete-array-built-ins”rel=“nofollow noreferer” https://isocpp.org/wiki/faq/freesshop-mgmt#del-array-built-ins

http://em>doesn t。 它只是appears。 显示未定义的行为<>的代码似乎在一眼中是“有效”的,就像一个带有诱骗的节目一样,在选择不好的试验套体上似乎会变成“工作罚款”。

它不明确的行为。 由于“此时此刻工作”属于“未界定”一类,因此可以在某些平台上为一些汇编者开展工作。 然而,这还未做。 你们是否试图用像这样的 des子处理一系列物体,看看看谁是谁?

页: 1

在微软视频演播室的大多数版本中,这实际上都是正确的。 然而,没有理由这样做,它完全走到你的平台上。

删除的意思是,这是在汇编时间时不知道规模的特殊情形,分配框架可能希望以不同方式处理(并优化删除案例)。

严格地说,delete pointer ToBaseClass 汇编时也不知道数量,但通过虚拟表格解决,汇编者知道,这个类别在汇编时间是多变的。

如果你误用[],那么在更换分配器(发送人、各种束缚器等)的工具以及用户可能使用的习惯分配器方面也可能会遇到问题。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?