c++ - declaring a templated method inside a templated class -


i attempting add templated method templated class. referred this answer syntax not working.i added second method called tester templated. have

template <typename t,typename u> struct foo {      void test();      template<typename v>     void tester(v lhs); };  template<typename t,typename u> void foo<t,u>::test() {     std::cout << "hello world" ; }  template<typename t,typename u> template<typename v> void foo<t,u>::tester<v>(v lhs) {     std::cout << "hello world " << lhs ; }  int main()  {     foo<int,int> t;     t.test();       t.tester<int>(12); } 

i getting error method tester error get

  main.cpp:20:31: error: non-type partial specialization 'tester<v>' not allowed  void foo<t,u>::tester<v>(v lhs) { 

any suggestions on why getting error or might doing wrong ?

comment inline in corrected code below:

#include <iostream>  template <typename t,typename u> struct foo {      void test();      template<typename v>     void tester(v lhs); };  template<typename t,typename u> void foo<t,u>::test() {     std::cout << "hello world" ; }  /*  * change made template function definition  */ template<typename t,typename u> template<typename v> void foo<t,u>::tester(v lhs) {     std::cout << "hello world " << lhs ; }  int main()  {     foo<int,int> t;     t.test();       t.tester<int>(12); } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -