1

Event.h

 class Event {
   template <typename T, void(T::*MF)(int)>
   void temp_callback(int r){
   }

   template <typename T, void(T::*MF)(int)>
   void temp_add(T *obj, int a){
     obj->testobj3<T, MF>(obj, a); // throws error here
     temp_callback<T, MF>(a);
   }
 }

Test.h

 class Test{       
   void testobj(int r);
   void testobj2();

   template <typename T, void(T::*MF)(int)>
   void testobj3(T *obj, int a){
   }
 }

Test.cc

 void Test::testobj2(){
   Event eve;
   eve.temp_add<Test, &Test::testobj>(this, 1);
 }

 int main() {
   Test t;
   t.testobj2();
 }

Above code throws an error saying "error: expected primary-expression before ‘,’ token". If I instead define a non-template function for testobj3 and call obj->testobj3 (Where it's throwing error), it works fine. Not sure why the templated call would throw an error?

Thanks much for your time in advance!

MaC
  • 41
  • 5
  • Your question was marked as a duplicate of [Where and why do I have to put the “template” and “typename” keywords?](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords). It does answer your question, but, in case you're still stuck: you need to add `template` to your call: `obj->template testobj3(obj, a);` – Not a real meerkat Sep 15 '18 at 16:59

0 Answers0