Created
September 17, 2012 20:09
-
-
Save motonacciu/3739485 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 Instance { | |
| std::shared_ptr<const Instance> ref; | |
| int value; | |
| public: | |
| Instance (const std::shared_ptr<const Instance>& other, int value) : | |
| ref(other), value(value) { } | |
| void setRef(const std::shared_ptr<const Instance>& ref) { | |
| this->ref = ref; | |
| } | |
| }; | |
| class InstanceMgr { | |
| std::vector<std::shared_ptr<const Instance>> repos; | |
| public: | |
| void create() { | |
| auto i1 = std::make_shared<Instance>(nullptr, 0); | |
| auto i2 = std::make_shared<const Instance>(i1, 0); | |
| i1->setRef(i2); // creating a cycle | |
| repos.emplace_back(i1); | |
| repos.emplace_back(i2); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment