我正在阅读“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/