Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102835922
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, Feb 24, 16:43
Size
405 B
Mime Type
text/x-c
Expires
Wed, Feb 26, 16:43 (2 d)
Engine
blob
Format
Raw Data
Handle
24429165
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