c++ implementation