C++ implementation