Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78369669
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
Tue, Aug 20, 08:29
Size
405 B
Mime Type
text/x-c
Expires
Thu, Aug 22, 08:29 (2 d)
Engine
blob
Format
Raw Data
Handle
20034523
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