Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90338801
shared_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
Thu, Oct 31, 16:42
Size
304 B
Mime Type
text/x-c
Expires
Sat, Nov 2, 16:42 (2 d)
Engine
blob
Format
Raw Data
Handle
22054580
Attached To
R7571 SP4E-TB-TL-FR
shared_pointers.cpp
View Options
#include <iostream>
#include <memory>
std::shared_ptr<double> get_vector(int n) {
return std::shared_ptr<double>(new double[n]);
}
int main() {
std::shared_ptr<double> ptr1 = get_vector(10);
std::shared_ptr<double> ptr2 = ptr1;
// memory of pointer freed when ptr1 and ptr2 are out of scope
}
Event Timeline
Log In to Comment