Skip to content

Instantly share code, notes, and snippets.

@taeguk
Last active May 1, 2016 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taeguk/1c23e5e00c51f7ad36213081cd094438 to your computer and use it in GitHub Desktop.
Save taeguk/1c23e5e00c51f7ad36213081cd094438 to your computer and use it in GitHub Desktop.
#include <iostream>
class B;
class A {
public:
unsigned int checksum;
private:
B& b;
A(B& b)
:b(b), checksum(0x12341234)
{}
public:
static A& A::GetObject();
};
class B {
public:
unsigned int checksum;
private:
A& a;
B(A& a)
:a(a), checksum(a.checksum)
{}
public:
static B& GetObject() {
static B b(A::GetObject());
return b;
}
};
A& A::GetObject() {
static A a(B::GetObject());
return a;
}
int main()
{
std::cout << "A : " << std::hex << A::GetObject().checksum << std::endl;
std::cout << "B : " << std::hex << B::GetObject().checksum << std::endl;
return 0;
}
@taeguk
Copy link
Author

taeguk commented May 1, 2016

-----execution result----- (visual studio 2013 professional)
A : 12341234
B : 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment