This discussion is archived
2 Replies Latest reply: Nov 28, 2013 12:01 AM by c05a9c8e-e5e4-428f-8343-25ba1306199a RSS

Can't compile template with pointer to member function template argument

c05a9c8e-e5e4-428f-8343-25ba1306199a Newbie
Currently Being Moderated

Hello,

 

The following code doesn't compile using "Sun C++ 5.10 SunOS_sparc 2009/06/03" with the following error:

line 15: Error: Could not find a match for MyCallback<Param, Callee, Function>(Test*, int) needed in main()

However the same code compiles using g++ or "Sun C++ 5.12 SunOS_sparc Patch 148506-09 2013/02/21".

 

It seems to me that it is a compiler bug. Is there a workaround? Is there a patch for 5.10? Otherwise what is the minimal version of the compiler that fixes this bug?

 

Thank you, Petr

 

template<typename Param, class Callee, void (Callee::*Function)(Param)>
void MyCallback(Callee* callee, Param param) {
  (callee->*Function)(param);
}

 

class Test {
public:
  void test(int x) {
    //std::cout << "test(" << x << ")" << std::endl;
  }
};

 

int main() {
  Test t;
  MyCallback<int, Test, &Test::test>(&t, 1);
  return 0;
}

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points