Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested template classes with pointer-to-method not compiled in clang++

SSCCE of my problem is:

template <class T> class MyClass
{
  template <void (MyClass::*M)() const> struct wrapper
  {
    virtual void call();
  };
};

template <typename T>
template <void (MyClass<T>::*M)() const>
void MyClass<T>::wrapper<M>::call()
{
}

This code compiled in gcc but failed with error:

error: nested name specifier 'MyClass<T>::wrapper<M>::' for declaration does not refer into a class, class template or class template partial specialization
void MyClass<T>::wrapper<M>::call()
 ~~~~~~~~~~~~~~~~~~~~~~~~~^

in clang++. Why?

In class call definition solves the problem, I know. Any non pointer-to-method templates works fine everywhere. Experiments with template/typename has no result.

like image 611
dyomas Avatar asked Jul 29 '15 21:07

dyomas


1 Answers

Possible workaround: consider using std::function instead of wrapper. It is not exactly the same (less constraint on which function pointers are acceptable) but it will compile on clang++ and simplify your code.

#include <functional>

template <class T> class MyClass
{
    typedef std::function<void(void) const > wrapper;
};
like image 146
Uri Brecher Avatar answered Nov 09 '22 12:11

Uri Brecher