C++ (Qt)int main(int argc, char *argv[]){ Foo* pobj = new Foo; Foo2* pobj2 = new Foo2; QObject* pobjCopy = something ? pobj : pobj2; QObject* pobj2Copy = something ? pobj2 : pobj; //do something... delete pobj; delete pobj2;}