cpp implementation of Remove Element