VS&G++ 重载operator delete的bug(已解决)
2009-04-17 20:03:36 来源:WEB开发网#include <iostream>
using namespace std;
struct foo
{
};
namespace n1
{
void* operator new( size_t size )
{
void* raw = ::operator new( size );
cout << "alloc: " << raw << endl;
return raw;
}
void operator delete( void* raw )
{
cout << "free : " << raw << endl;
::operator delete( raw );
}
void test()
{
delete new int;
delete new foo;
}
}
int main()
{
n1::test();
return 0;
}
VS的Bug最大,它根本就不调用我重载的operator new和operator delete
g++的Bug很有趣,delete new foo 很正确,但 delete new int 却只调用了operator new,没调用 operator delete.
--------------- 最佳答案 ---------------
re: VS&G++ 重载operator delete的bug 2008-11-26 13:07 scu319hy
An allocation function shall be a class member function or a global function; a program is ill-formed if an
allocation function is declared in a namespace scope other than global scope or declared static in global
scope.
编译器没错,是你错了...
VC只是没有报错,而你的GCC才真的是错了.不过我用的4.3版结果很对.
- ››VSFTP服务器配置详解
- ››VS2008 安装失败(“Web 创作组件”无法)的解决办...
- ››VS调用存储过程
- ››VS2005无法远程连接SQL数据库问题
- ››VS2010 Express中文版已经发布至MSDN
- ››VS2008C# 开发 Windows Mobile 6.0程序应注意的几...
- ››VS08中最简单也最实用的Ajax无刷新技术
- ››VS2003+nds OR VS2003+carbide.vs 开发 Symbian 程...
- ››VS2008 平台下进行 Windows Mobile 开发环境的搭建...
- ››VS 2010/.NET 4 RC版 发布了
- ››VS 2010的Intellisense相关崩溃的修补
- ››VS2010 Extension实践
更多精彩
赞助商链接