参考资料
#include <iostream> using namespace std;
void f(){ cout << "hello, world" << endl; }
int main() { void (*(*p)) () = new (void (*[7]) ()); for(int i = 0; i < 7; i++) { p[i] = f; }
for(int i = 0; i < 7; i++) { (p[i])(); }
delete [] p;
return 0; } |
来验证下应该使用delete[];
覆盖operator new 和 operator new[];
void* operator new(std::size_t count){
cout << "new" << endl;
return malloc(count);
}
void* operator new[](std::size_t count){
cout << "new[]" << endl;
return malloc(count);
}
结果如下: