new operator for memory allocation on heap

后端 未结 2 1215
执笔经年
执笔经年 2020-12-25 12:09

I was looking at the signature of new operator. Which is:

void* operator new (std::size_t size) throw (std::bad_alloc);

But when we use thi

2条回答
  •  半阙折子戏
    2020-12-25 12:42

    You confuse new expression with operator new() function. When the former is compiled the compiler among other stuff generates a call to operator new() function and passes size enough to hold the type mentioned in the new expression and then a pointer of that type is returned.

提交回复
热议问题