c++标准库第二版中文版第99页,unique_ptr。以下:#include<memory>javascript voidd f() { std::

C++第五章习题解答_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
C++第五章习题解答
上传于||文档简介
&&同​济
大小:9.59KB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢&memory& - C++ Reference
Memory elements
This header defines general utilities to manage dynamic memory:
Allocators
Default allocator (class template
)Allocator arg (object
)Allocator arg type (class
)Allocator traits (class template
)
Managed pointers
Automatic Pointer [deprecated] (class template
)Reference to automatic pointer (class template
)Shared pointer (class template
)Weak shared pointer (class template
)Unique pointer (class template
)Default deleter (class template
)
Functions and classes related to shared_ptr:
Make shared_ptr (function template
)Allocate shared_ptr (function template
)Static cast of shared_ptr (function template
)Dynamic cast of shared_ptr (function template
)Const cast of shared_ptr (function template
)Get deleter from shared_ptr (function template
)Owner-based less-than operation (class template
)Enable shared_from_this (class template
)
Uninitialized memory
Raw storage iterator:
Raw storage iterator (class template
)
Temporary buffers:
Get block of temporary memory (function template
)Return block of temporary memory (function template
)
Specialized algorithms:
Copy block of memory (function template
)Copy block of memory (function template
)Fill block of memory (function template
)Fill block of memory (function template
)
Memory model
Pointer traits (class template
)Pointer safety enum (enum class
)Declare pointer as reachable (function
)Undeclare pointer as reachable (function template
)Declare memory block as containing no pointers (function
)Undeclare memory block as containing no pointers (function
)Get pointer safety (function
)Align in range (function
)Address of object or function (function template
)
enum classes:
functions:问两道c++的题#include&iostream.h& void f(int &x,int &y) { temp=x;x=y;y= } void main()_百度知道unique_ptr::unique_ptr - C++ Reference
unique_ptr
public member function
std::::unique_ptr
default (1)
constexpr unique_ptr()
from null pointer (2)
constexpr unique_ptr (nullptr_t) noexcept : unique_ptr() {}
from pointer (3)
explicit unique_ptr (pointer p)
from pointer + lvalue deleter (4)
unique_ptr (pointer p,
typename conditional&is_reference&D&::value,D,const D&& del)
from pointer + rvalue deleter (5)
unique_ptr (pointer p,
typename remove_reference&D&::type&& del)
move (6)
unique_ptr (unique_ptr&& x)
move-cast (7)
template &class U, class E&
unique_ptr (unique_ptr&U,E&&& x)
move from auto_ptr (8)
template &class U&
unique_ptr (auto_ptr&U&&& x)
copy (deleted!) (9)
unique_ptr (const unique_ptr&) =Construct unique_ptr
Constructs a
object, depending on the signature used:
default constructor (1), and (2)
The object is empty (owns nothing), with value-initialized
construct from pointer (3)
The object takes ownership of p, initializing its
to p and value-initializing its .
construct from pointer + lvalue deleter (4)
The object takes ownership of p, initializing its
to p, and using a copy of d as
(unless D is a reference type, in which case, d is used directly).
construct from pointer + rvalue deleter (5)
The object takes ownership of p, initializing its
to p and moving d into the object to be used as .
move constructors (6) and (7)
The object acquires the content managed by x, moving into the object both its
(of which it takes ownership) and its
(unless x's deleter type is a reference, in which case the deleter is copied instead of moved).
construct by moving auto_ptr (8)
The object acquires the content managed by x, initializing its
as if by calling x. (taking ownership of the pointer), and value-initializing its .
copy construction (9)
Copy construction is disabled for objects of type
(see move constructors, 6 and 7).
The specialization of
for arrays with runtime length (unique_ptr&T[],D&) does not support constructors (7) and (8), and does not accept types convertible to pointer (except pointer itself) as argument p (most notably pointers to types derived from element_type are not accepted).
Parameters
Pointer whose ownership is taken over by the object.
This pointer value shall not be already managed by any other managed pointer (i.e., this value shall not come from calling member
on a managed pointer).
pointer is a member type, defined as the pointer type that points to the type of object managed.
Deleter object to be used to release the owned object.
D refers to 's second template parameter, which describes its deleter type.
U* shall be implicitly convertible to T* (where T is 's first template parameter).
1234567891011121314151617181920212223242526
// unique_ptr constructor example
#include &iostream&
#include &memory&
int main () {
std::default_delete&int&
std::unique_ptr&int& u1;
std::unique_ptr&int& u2 (nullptr);
std::unique_ptr&int& u3 (new int);
std::unique_ptr&int& u4 (new int, d);
std::unique_ptr&int& u5 (new int, std::default_delete&int&());
std::unique_ptr&int& u6 (std::move(u5));
std::unique_ptr&int& u7 (std::move(u6));
std::unique_ptr&int& u8 (std::auto_ptr&int&(new int));
std::cout && "u1: " && (u1?"not null":"null") && '\n';
std::cout && "u2: " && (u2?"not null":"null") && '\n';
std::cout && "u3: " && (u3?"not null":"null") && '\n';
std::cout && "u4: " && (u4?"not null":"null") && '\n';
std::cout && "u5: " && (u5?"not null":"null") && '\n';
std::cout && "u6: " && (u6?"not null":"null") && '\n';
std::cout && "u7: " && (u7?"not null":"null") && '\n';
std::cout && "u8: " && (u8?"not null":"null") && '\n';
u3: not null
u4: not null
u7: not null
u8: not null
unique_ptr assignment (public member function
)Reset pointer (public member function
)Destroy unique_ptr (public member function
)
enum classes:
functions:
member functions:
non-member overloads:c++程序设计(第二版)课后作业答案_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
c++程序设计(第二版)课后作业答案
上传于||文档简介
&&1​.​C​+​+​程​序​设​计​(​第​二​版​)​课​后​作​业​答​案​
​
.​清​华​大​学​出​版​
​
​第​一​章​ ​习​题​答​案​
​
.
​
​ ​c​o​u​t​&​l​t​;​&​l​t​;​&​q​u​o​t​;​E​n​t​e​r​ ​t​w​o​ ​n​u​m​b​e​r​s​&​q​u​o​t​;​;​
​
​ ​c​i​n​&​g​t​;​&​g​t​;​a​&​g​t​;​&​g​t​;​b​;​
​
​ ​c​=​a​*​b​;​
​
​ ​c​o​u​t​&​l​t​;​&​l​t​;​&​q​u​o​t​;​a​*​b​=​&​q​u​o​t​;​&​l​t​;​&​l​t​;​c​;​
​
.
​
​#​i​n​c​l​u​d​e​ ​&​l​t​;​i​o​s​t​r​e​a​m​.​h​&​g​t​;​
​
​v​o​i​d​ ​m​a​i​n​(​)​
​
​{​f​l​o​a​t​ ​a​,​b​,​c​;​
​
​ ​c​o​u​t​&​l​t​;​&​l​t​;​&​q​u​o​t​;​请​任​意​输​入​三​个​数​:​&​q​u​o​t​;​;​
​
​ ​c​i​n​&​g​t​;​&​g​t​;​a​&​g​t​;​&​g​t​;​b​&​g​t​;​&​g​t​;​c​;​
​
​ ​c​o​u​t​&​l​t​;​&​l​t​;​e​n​d​l​&​l​t​;​&​l​t​;​&​q​u​o​t​;​其​和​为​:​&​q​u​o​t​;​&​l​t​;​&​l​t​;​a​+​b​+​c​;​
​
​…​…​…​…​详​见​文​档​。
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩7页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢

我要回帖

更多关于 c void 的文章

 

随机推荐