Skip to content

Instantly share code, notes, and snippets.

@Ge0
Created June 2, 2019 17:32
Show Gist options
  • Save Ge0/ef398b654df5679a43f7418a3088ea7c to your computer and use it in GitHub Desktop.
Save Ge0/ef398b654df5679a43f7418a3088ea7c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <memory>
class B;
class A {
public:
A() : m_b(nullptr){}
void setB(std::shared_ptr<B> b) {
m_b = b;
}
private:
std::shared_ptr<B> m_b;
};
class B {
public:
B() : m_a(nullptr){}
void setA(std::shared_ptr<A> a) {
m_a = a;
}
private:
std::shared_ptr<A> m_a;
};
int main(int argc, char* argv[]) {
std::shared_ptr<A> a = std::make_shared<A>();
std::shared_ptr<B> b = std::make_shared<B>();
a->setB(b);
b->setA(a);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment