C++ Code for generating object