是什么让 placement new 调用对象的构造函数?

What makes placement new call the constructor of an object?

来自here

The Standard C++ Library provides a placement form of operator new declared in the standard header as:

void *operator new(std::size_t, void *p) throw ();

Most C++ implementations define it as an inline function:

inline
void *operator new(std::size_t, void *p) throw () 
{
    return p;
}

It does nothing but return the value of its second parameter. It completely ignores its first parameter. The exception-specification throw () indicates that the function isn't allowed to propagate any exceptions.

我知道 placement new 只是对 operator new 的重载,而且它在给定的内存地址上调用构造函数。

但是是什么让它调用构造函数呢?它只需要一个指针并再次 returns 它。拿一个指针然后返回它有什么意义?为什么要将值传递给函数以将其取回?

But what makes it call the constructor?

operator newsemantics

有关详细信息,阅读 C++11 标准 n3337 about new expressions 或该标准的更新版本。

当你定义一些operator new时,稍后使用它会调用构造函数。根据 C++ 的定义。

我推荐好好读一读C++ programming book

练习:使用 malloc, the placement new, and some throw expression.

定义 usual operator new(在你的 class MyClass 中)