rewrite with c++