c++ - C++中的新运算符

标签 c++ new-operator

我正在阅读“Thinking in c++”的第 13 章。 以下内容来自本书。

MyType *fp = new MyType(1, 2);

at runtime, the equivalent of malloc(sizeof(MyType)) is called, and the constructor for MyType is called with the resulting address as the this pointer, using (1, 2) as the argument list. By the time the pointer is assigned to fp.

我被粗体字弄糊涂了。什么意思?

最佳答案

这是一个非常松散的解释,但它基本上是说结果是一个内存位置,就像 malloc 会返回一样,并且在那个内存位置构造一个对象(this 是指向当前对象的指针)使用带有该参数列表的构造函数。

关于c++ - C++中的新运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14842492/

相关文章:

c++ - Boost.log V1 编译错误

c++ - 如何使用 QT 命名空间中使用的重载 new 运算符

ruby - 在 Ruby 中, 'new' 和 'initialize' 之间的关系是什么?初始化时如何返回nil?

c++ - 如何在 C++ 中使用 new 运算符初始化内存?

c++ - 计数 __VA_ARGS__ MSVC 给出意想不到的结果

c++ - 重载引用与 const 引用

c++ - 在 C 中比较相同的浮点值

magento - Magento 如何将订购的产品保存在数据库中?

c++ - 检索函数内用 operator new 分配的类指针对象成员的值的问题

c++ - 是否有适用于 Mac OS X 的好(最好是免费的)面向对象建模应用程序?