码迷,mamicode.com
首页 > 编程语言 > 详细

C++中new的二三事

时间:2014-08-05 13:53:49      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   div   line   

 1 #include <iostream>
 2 using std::cout;
 3 using std::endl;
 4 #define new New (__FILE__,  __LINE__) 
 5 
 6 void * operator new (size_t size,  const char * filename,  int lineno) 
 7 { 
 8  cout <<"NEW: filename =" <<filename <<",  lineno =" <<lineno << endl; 
 9  cout <<"Lineno? "<< size << endl;
10  return operator new (size); 
11 }
12 int main (int argc,  char ** argv) 
13 { 
14  int * p = new  (__FILE__,  __LINE__) int ; 
15  cout <<"Hello World!" <<endl; 
16  delete p; 
17  return 0; 
18 } 

是的,一切都是因为在一篇老外的博客里面看到了第14行,因此我要挖个坑来埋自己。

C++中new的二三事,布布扣,bubuko.com

C++中new的二三事

标签:style   blog   color   os   io   ar   div   line   

原文地址:http://www.cnblogs.com/kevingeek/p/3891902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!