#deep extend written using c++