free_sky_moon 2015-05-04 09:29 采纳率: 0%
浏览 2519

关于使用 new BYTE(100)使用之后delete出错,错误信息:堆栈被破坏

错误如题,代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct name
{
char name_char;
int fi;
};

struct student_info
{
int id;
long student_id;
int class_num;
name cn[1];
};
void main()
{
int len_byte = sizeof(student_info)+25*sizeof(name);
student_info* student = (student_info*) new BYTE(len_byte);

student->id = 11;
student->class_num = 11;
student->student_id = 123434;
for(int i = 0 ; i < 26 ; i ++)
{
    student->cn[i].name_char = (char)(i+22);
    student->cn[i].fi = i;
}

cout<<"hello C++"<<endl;
delete student;//在执行这个语句的时候VS会抛出异常,

}

错误显示如下:
其原因可能是堆被损坏,这说明 test_other_func_code.exe 中或它所加载的任何 DLL 中有 Bug。

原因也可能是用户在 test_other_func_code.exe 具有焦点时按下了 F12。

  • 写回答

2条回答 默认 最新

  • threenewbee 2015-05-04 12:34
    关注

    student_info* student = new student_info();
    就可以了。
    你这样也不能改变cn数组的大小

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题