rewrite in C++