Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
shared_ptr
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//g++ 5.4.0 #include <iostream> #include <memory> #include <vector> struct Component: public std::enable_shared_from_this<Component> { std::vector<std::shared_ptr<Component>> children; std::shared_ptr<Component> parent; void add(std::shared_ptr<Component> v) { children.push_back(std::move(v)); children.back()->parent = shared_from_this(); } Component() { std::cout << "Component::Component()" << std::endl; } ~Component() { std::cout << "Component::~Component()" << std::endl; } }; int main() { std::shared_ptr<Component> component1 = std::make_shared<Component>(); std::shared_ptr<Component> component2 = std::make_shared<Component>(); component1->add(std::move(component2)); }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.63 sec, absolute running time: 0.07 sec, cpu time: 0.01 sec, memory peak: 3 Mb, absolute service time: 0,71 sec
edit mode
|
history
Component::Component() Component::Component()