and rewrite in cpp