operator new 重载的问题

Boy_Vc 2003-04-03 02:28:06
void * Chunk::operator new (size_t size, int bytes)
{

if (bytes > MAX_CHUNK_SIZE)
{
cerr<<"trying to make chunk of size "<<bytes<<"\n";
}

void *it = new char[size + bytes];

return it;
}

调用时, Chunk *newchunk = new(100) EST_Chunk;
在DevC++厘可以成功的调Chunk::new,而在vc6里,却编译不通过,我个人觉得以上调用方式,参数不对,vc6不通过是对的,但是,DevC却能执行,是什么原因呢

...全文
41 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Boy_Vc 2003-04-03
  • 打赏
  • 举报
回复
e:\project\try2\chunk\chunk.cpp(181) : warning C4291: 'void *__cdecl Chunk::operator new(unsigned int,int)' : no matching operator delete found; memory will not be freed if initialization throws an exception
e:\project\try2\chunk\chunk.h(80) : see declaration of 'new'

以上是vc6里的编译错误信息void EST_Chunk::operator delete (void *it)

下面是重载的delete函数,有错吗
void EST_Chunk::operator delete (void *it)
{
delete it;
}




69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧