Suppose I have the following two classes:
template<typename T>
struct Base
{
void foo();
};
struct Derived : Base<Derived> {};
I can do this:
void (Derived::*thing)() = &Derived::foo;
And the compiler is happy (as I would expect).
When I put this in two levels of templates suddenly it explodes:
template<typename T, T thing>
struct bar {};
template<typename T>
void foo()
{
bar<void (T::*)(),&T::foo>{};
}
int main()
{
foo<Derived>(); // ERROR
foo<Base<Derived>>(); // Works fine
}
This fails with:
non-type template argument of type 'void (Base<Derived>::*)()' cannot be converted to a value of type 'void (Derived::*)()'
Why does the simple case work and the more complicated one fail? I believe this is related to this question but am not entirely sure....