写了一个bug----使用已经被删除的内存
#include <iostream>
#include <stdio.h>
#include <memory.h> using namespace std;
const int NN = ;
class Piece
{
private:
int r;
int c;
int** p;
public:
Piece()
: r(), c()
{
p = nullptr;
}
Piece(int r, int c, int (*pp)[NN])
{
this->r = r;
this->c = c;
this->p = new int*[r]; for(int i = ; i < r; i++)
{
this->p[i] = new int[c];
memcpy(this->p[i], pp[i], c * sizeof(int));
}
}
~Piece()
{
cout<<"delete"<<endl;
for(int i = ; i < r; i++)
delete[] p[i];
delete this->p;
}
int getR()
{
return this->r;
}
int getC()
{
return this->c;
}
int ** getP()
{
return this->p;
} }; int N;
int r, c;
int m[][];
Piece piece[NN];
int pi = ;
void dump()
{
for(int i = ; i < pi; i++)
{
for(int j = ; j < piece[i].getR(); j++)
{
for(int k = ; k < piece[i].getC(); k++)
{
cout << piece[i].getP()[j][k];
}
cout << endl;
}
cout << endl;
}
}
int main()
{
freopen("d://1.text", "r", stdin);
while (cin >> N && N)
{
memset(m, , sizeof(m));
memset(piece, , sizeof(piece));
int p[NN][NN];
pi = ;
for(int i = ; i <= N; i++)
{
scanf("%d %d", &r, &c);
for(int j = ; j < r; j++)
for(int k = ; k < c; k++)
{
char t;
cin >> t;
if(t == '')
p[j][k] = ;
else
p[j][k] = i;
}
Piece pp(r, c, p);
piece[pi++] = pp;
cout<<"for end"<<endl;
}
}
//dump();
return ; }
输出
for end //循环结束输出
delete //删除pp对象
main end //main函数结束
//下面是5个delete 和 const int NN=5对应
delete
delete
delete
delete
delete
//所以, delete 0 永远都是安全的
//注意前面有个
memset(piece, 0, sizeof(piece));
写了一个bug----使用已经被删除的内存的更多相关文章
- NDK中使用pthread多线程中自己写的一个BUG
在使用pthread进行NDK中的多线程开发时,自己写了一个BUG, void *darkGrayThread(void *args) { ThreadParam *param = (ThreadPa ...
- 写了一个bug,最后却变成了feature,要不要修呢?
事情是这样子的,前不久接到一个需求,为一个游戏开发礼包码功能 通常一款游戏运营期间会搞各种各样的活动吸引玩家,其中最常见的就是发放礼包, 玩家可以通过礼包码兑换礼包. 用礼包码兑换礼包有个一限制,游 ...
- 终于,帮开发写了一个bug
写在文章的开头 最近项目比较紧,尤其前端的的需求比较多,作为一名测试,也会些vue,本着加快项目进度的美好想法,就自告奋勇的向组长承接了一部分开发的任务,其中有个需求需要在我们的广告管理后台新增一个上 ...
- 如何写出一个让人很难发现的bug?
程序员的日常三件事:写bug.改bug.背锅.连程序员都自我调侃道,为什么每天都在加班?因为我的眼里常含bug. 那么如何写出一个让(坑)人(王)很(之)难(王)发现的bug呢? - 1 -新手开发+ ...
- 写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我
写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我 1.HttpUtil工具类,用于模拟用户登录以及爬取网页: using System; using ...
- 浅谈如何写出一个让(坑)人(王)很(之)难(王)发现的bug
该文章内容来自脚本之家,原文链接:https://www.jb51.net/news/598404.html 程序员的日常三件事:写bug.改bug.背锅.连程序员都自我调侃道,为什么每天都在加班?因 ...
- 实现一个最简单的VIM文本编辑器(可能有bug,随便写了一个)
简单的写了一个文本编辑器,功能很简单,但足以把文件IO相关的操作熟悉了,可能功能或者分配的大小还不够完善.请参考参考: #include <stdio.h> #include <co ...
- sqlite在Android上的一个bug:SQLiteCantOpenDatabaseException when nativeExecuteForCursorWindow
更多内容在这里查看 https://ahangchen.gitbooks.io/windy-afternoon/content/ ::-/com.company.product W/System.er ...
- [android开发IDE]adt-bundle-windows-x86的一个bug:无法解析.rs文件--------rs_core.rsh file not found
google的android自带的apps写的是相当牛逼的,将其导入到eclipse中方便我们学习扩展.可惜关于导入的资料太少了,尤其是4.1之后的gallery和camera合二为一了.之前导4.0 ...
随机推荐
- ML平台_Angel参考
Angel 是腾讯开源基于参数服务器(Parameter Server)理念的机器学习框架(为支持超大维度机器学习模型运算而生).核心设计理念围绕模型,它将高维度的大模型切分到多个参数服务器节点,并通 ...
- python cntl使用
import sys 2 import time 3 import fcntl 4 5 class FLOCK(object): 6 7 def __init__(self, name): 8 sel ...
- 在64位平台上的Lucene,应该使用MMapDirectory[转]
http://blog.thetaphi.de/2012/07/use-lucenes-mmapdirectory-on-64bit.html 从3.1版本开始,Lucene和Solr开始在64位的W ...
- Elasticsearch 5.2.x 使用 Head 插件连接不上集群
如果访问elasticsearch出现跨域的问题,如下: 修改elasticsearch.yml文件 vim $ES_HOME$/config/elasticsearch.yml # 增加如下字段 h ...
- bzoj5050: 建造摩天楼
Description 属于小Q管辖的n座摩天楼从左往右排成一排,编号依次为1到n,第i座摩天楼的高度为h_i.小Q会进行m次以下两种 操作之一: 2 l r,询问h_l+h_{l+1}+...+h_ ...
- 廖雪峰Java5集合-4Set-1使用Set
集合 Set用于存储不重复的元素集合: boolean add(E e) boolean remove(Object o) boolean contains(Object o) int size() ...
- 廖雪峰Java5集合-2List-1使用List
1.List定义 List是一种有序链表: List内部按照元素的先后顺序存放 每个元素都可以通过索引确定自己的位置 类似数组,但大小可变 //List<E>是一种有序链表: //* Li ...
- Windows平台下使用CodeBlocks+GCC编译器生成动态dll,C#调用报错
报无法加载dll错误,解决方法: 1) 编译选择设置成x86,即-m322) 必须在c#程序目录下加上libgcc_s_dw2-1.dll
- linux 安装软件各种错误集锦及解决方法
1.最小化安装了centos, 但是使用ifconfig命令时候出现”bash ifconfig command not found” .解决方法:yum -y install net-tools.x ...
- 第7章 网络层协议(2)_ICMP协议
2. ICMP协议 2.1 ICMP报文(Internet Control Message Protocol)的类型 报文类型 类型值 代码 描述 请求报文 8 0 请求回显报文 响应报文 0 0 回 ...