#include "bidi_ptr.h" #include struct X; struct Y; struct Z; struct X { X():m_pY(this), m_pX(this){} void test() const; void notify() const { std::cerr << "X::notify()\n"; } bidi_ptr m_pY; bidi_ptr m_pX; }; struct Y { Y():m_pX(this){} void notify() const { std::cerr << "Y::notify()\n"; } bidi_ptr m_pX; }; void X::test() const { std::cerr << "X::test()\n"; if(m_pX) m_pX->notify(); if(m_pY) m_pY->notify(); } int main() { X x; { Y y; connect(x.m_pY, y.m_pX); connect(x.m_pX, x.m_pX); x.test(); } x.test(); return 0; }