add a template method c++ code