#include class foo { public: int a; }; class test2 { public: test2() {f=new foo();} ~test2() {delete f;} foo* f; }; test2 foo1() { } int main(int argc, char** argv) { test2 t; test2 c; t = foo1(); std::cerr << foo1().f->a << std::endl; return 0; }