第一个括号是做什么的?
// TArray<struct FBatchedLine> BatchedLines; // declared in LineBatchComponent.h
new(BatchedLines) FBatchedLine(Start, End, Color, LifeTime, Thickness, DepthPriority);
new operator参考说它是placement_params
:
如果提供了placement_params,则将它们作为附加参数传递给分配函数
我想它直接在给定数组BatchedLines
的末尾创建对象,但我不确定它是如何工作的完全理解的。
placement_params
什么时候有用?
注意
对于那些有权访问github UnrealEngine repo的人来说,here是源文件。
这是放置新语法。它在FBatchedLine
指向的内存中使用构造函数参数BatchedLines
构造一个(Start, End, Color, LifeTime, Thickness, DepthPriority)
类型的对象。调用之后,BatchedLines
可用于引用构造的对象。
非正式地,您可以想象使用BatchedLines
作为this
来调用构造函数。
文字:palcement_params没有在reference C++ page中解释。根据英文含义:指针通常放在数组中的位置。这是boost的代码示例
T* buffer;
size_t write_index;
new (buffer + write_index) T(t); // copy-construct
实质上,您将类型为T的新对象放入缓冲区的write_index位置。