#include <stdio.h>
#include <vector.h>
#import <objc/Object.h>

struct C {
    C() { i = 0; }
    void p() { printf("%d\n", i); }
    int i;
};

@interface D : Object {
    C c;
    std::vector<int> is;
}
- init;
- (void)p;
@end

@implementation D
- init {
    [super init];
    c = C::C();
    is.push_back(2);
    return self;
}
- (void)p {
    c.p();
    for (std::vector<int>::const_iterator ite = is.begin();
         ite != is.end(); ++ite)
    {
        printf("%d\n", *ite);
    }
}
- (int)v {
    return c.i;
}
- free {
    puts("free");
    return [super free];
}
@end

template <class ObjcClass>
struct AutoObjc {
    id o;
    AutoObjc() {
        o = [[ObjcClass alloc] init];
    }
    ~AutoObjc() {
        [o free];
    }
};

int main(int argc, char* argv[]) {
    id d = [D new];
    [d p];
    [d free];
    AutoObjc<D> aod;
    [aod.o p];
    printf("%s\n", [aod.o v][argv]);
    return 0;
}
