#include <iostream>                    // Ex31
using namespace std;
struct T2;                            // forward declaration, no body
struct T1 {                            // T1 referencing T2 
    T2 &t2;                            // know about T2 from forward
    T1( T2 &t2 ) : t2( t2 ) {}        // constructor initialize
    void g( int i );                // forward declaration
};
struct T2 {                            // T2 referencing T1
    T1 t1;
    T2() : t1( *this ) {}             // constructor initialize
    void f( int i ) {
        cout << "T2::f(" << i << ")" << endl;
        if ( i > 0 ) t1.g( i - 1 );
        cout << "T2::f(" << i << ")" << endl;
    }
};
void T1::g( int i ) {                // placed after both structure declarations
    cout << "T1::g(" << i << ")" << endl;
    if ( i > 0 ) t2.f( i - 1 );
    cout << "T1::g(" << i << ")" << endl;
}
int main() {
    T2 t2;
    t2.f( 5 );
    cout << endl;
    T1 t1( t2 );
    t1.g( 4 );
}
