add cpp version templatemethod pattern