Skip to content

Instantly share code, notes, and snippets.

@motonacciu
Created September 17, 2012 20:09
Show Gist options
  • Select an option

  • Save motonacciu/3739485 to your computer and use it in GitHub Desktop.

Select an option

Save motonacciu/3739485 to your computer and use it in GitHub Desktop.
#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