全局new和宏结合起来的一个小应用

 1 #include <iostream>
 2 using namespace std;
 3 
 4 void* operator new(size_t size, const char* file, int line)
 5 {
 6     cout << file << " : " << line << endl;
 7     cout << "size : " << size << endl;
 8     return ::new char[size];
 9 }
10 #define new new(__FILE__,__LINE__)
11 
12 int main()
13 {
14     int* a = new int;
15     delete a;
16 }

 

posted @ 2019-10-10 21:22  机智的小小帅  阅读(197)  评论(0编辑  收藏  举报