Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66392190
unique_pointers.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jun 10, 05:56
Size
405 B
Mime Type
text/x-c
Expires
Wed, Jun 12, 05:56 (2 d)
Engine
blob
Format
Raw Data
Handle
18215913
Attached To
R7571 SP4E-TB-TL-FR
unique_pointers.cpp
View Options
#include <iostream>
#include <memory>
std
::
unique_ptr
<
double
>
get_scalar
()
{
// create a unique pointer
return
std
::
make_unique
<
double
>
(
3
);
}
int
main
()
{
std
::
unique_ptr
<
double
>
ptr
=
get_scalar
();
// ... do what I need like...
std
::
cout
<<
*
ptr
;
// no need to delete scalar (will be automatically)
// cannot be copied => compilation error
// std::unique_ptr<double> ptr_copy = ptr;
}
Event Timeline
Log In to Comment