C++ recursive cutting