Abstact
之前看侯捷老师的C++面向对象开发上。老师讲了一个知识点,如下图:
在他的C++面向对象高级编程(下)课程中,侯捷老师讲了重载operator new,operator delete。这篇blog主要实现重载operator new/delete。并进行验证上图。Let`s go
Code:
下面是相应的代码。重载了operator new/delete/new[]/delete[]。
// .h
#include<iostream>
#include<cstdlib>
using std::cout;
using std::endl;
class Foo {
public:
int _id;
long _data;
Foo() :_id(0) {
cout << "default ctor this = " << this << " id=" <<_id<<endl; }
Foo(int i) :_id(i) {
cout << "ctor this= " << this << " id