Want to rewrite it on C++