C++ templates in class -


i have class, have methods. want use template 1 method, not class. can this?

class test {   private:     int i;   public:     test(int i);     int getval();     void setval(int i);      template <class type>     int testtemplate(type val); }; 

this legal , used in many cases, conversion function templates. see more info: http://en.cppreference.com/w/cpp/language/member_template

just please remember write function definition either inline or @ least in same file, otherwise can not compile. additionally, if there's no call function in project, won't generated, saves space.


Comments