Last active
May 1, 2016 08:19
-
-
Save taeguk/1c23e5e00c51f7ad36213081cd094438 to your computer and use it in GitHub Desktop.
This file contains 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> | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-----execution result----- (visual studio 2013 professional)
A : 12341234
B : 0