c++ - creating template function with different parameters -



c++ - creating template function with different parameters -

so illustration want create function add together 2 numbers , homecoming total.

template<typename t1, typename t2> t1 add( t1 n1, t2 n2 ){ homecoming n1 + n2; }

problems if t1 int , t2 float. function return int. want return float. there trick or way accomplish it?

yes

template<typename rt, typename t1, typename t2> rt add( t1 n1, t2 n2 ){ homecoming n1 + n2; }

now phone call like:-

add<float>(2,3.0);

c++ templates

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -