Try to write a C++ iimplementation