C++ Memory & Lifetime · 1 of 3
Move Semantics
AtomicRepsNavigation
Ownership in C++: RAII, the smart pointers, copies against moves, and the lifetime rules.
C++ Memory & Lifetime · 1 of 3
Move Semantics
C++ Memory & Lifetime · 2 of 3
RAII
#include <iostream>#include <string>#include <type_traits>struct Five { std::string* p; Five() : p(new std::string("x")) {} ~Five() { delete p; }};int main() { std::cout << std::boolalpha << std::is_copy_constructible<Five>::value;}C++ Memory & Lifetime · 3 of 3
shared_ptr & weak_ptr
#include <iostream>#include <memory>struct S : std::enable_shared_from_this<S> { std::shared_ptr<S> self; void keep() { self = shared_from_this(); } ~S() { std::cout << "s"; }};int main() { { auto s = std::make_shared<S>(); s->keep(); } std::cout << "|after";}Three of the 1,320 C++ Memory & Lifetime questions.
Keep going with C++ Memory & Lifetime, free