Created
September 21, 2017 22:41
-
-
Save b4284/baf0679ee9dd06be5182f7a9c859fadc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <memory> | |
| class A { | |
| public: | |
| A() {} | |
| A(int i) { | |
| std::cout << i << std::endl; | |
| } | |
| virtual ~A() { | |
| std::cout << "A DIE" << std::endl; | |
| } | |
| }; | |
| class B : public A { | |
| public: | |
| B(const char *s) { | |
| std::cout << s << std::endl; | |
| } | |
| ~B() { | |
| std::cout << "B DIE" << std::endl; | |
| } | |
| }; | |
| int main() { | |
| std::vector<std::unique_ptr<A>> av; | |
| av.push_back(std::move(std::unique_ptr<A>(new B("GOING INTO B")))); | |
| av.push_back(std::move(std::unique_ptr<A>(new A(5)))); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment