Namespaces
Variants

std::allocator<T>:: construct

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
定义于头文件 <memory>
void construct ( pointer p, const_reference val ) ;
(1) (C++11 前)
template < class U, class ... Args >
void construct ( U * p, Args && ... args ) ;
(2) (C++11 起)
(C++17 中弃用)
(C++20 中移除)

在由 p 指向的已分配未初始化存储中,使用全局 placement-new 构造类型为 T 的对象。

1) 调用 :: new ( ( void * ) p ) T ( val )
2) 调用 :: new ( ( void * ) p ) U ( std:: forward < Args > ( args ) ... )

目录

参数

p - 指向已分配未初始化存储的指针
val - 用作拷贝构造函数参数的值
args... - 使用的构造函数参数

返回值

(无)

缺陷报告

下列行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。

缺陷报告 适用标准 发布时行为 正确行为
LWG 402 C++98 若存在 T :: operator new ,程序可能不符合规范 改用全局替换 new 操作符

参见

[static]
在已分配的存储中构造对象
(函数模板)
在给定地址创建对象
(函数模板)
分配函数
(函数)