#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-

%require-our
%requires qore >= 0.8
%new-style

class T1 { 
    public { int id; *T1 a; *T1 b; *T1 c;} 
    constructor(int i) { id = i; } 
    destructor() { printf("deleting %d\n", id); } 
    set(*T1 aa) { a = aa; }
}
class T2 inherits T1 {constructor(int i) : T1(i) {}}
class T3 inherits T2 {constructor(int i) : T2(i) {}}

# t2.b, t3.a
# t3.a -> t1, t1.a -> t2, t2.(a -> t3, b -> t1)
# t3 (rcount=1), t2 (rcount=1), t1 (rcount=2)
T1 t1(1);
{
    T2 t2(2);
    t1.set(t2);
    t2.b = t1;
    {
        T3 t3(3);
        t2.set(t3);
        printf("before\n");
        t3.set(t1);
        printf("after\n");
    }
}
