0

I have a class Basis which is templated on another class DERIVED via CRTP. This class has an inner class which operates as a functor and does the bulk of the work

template <typename DERIVED>
class Basis {
  template <int M> // M is the degree of approximation
  class Functor {
    double operator()(Eigen::Matrix<double, M, 1> values) {
      // Use specific function in DERIVED
    ...
    }
  };
...
};

So a specific class like Fourier looks something like

class Fourier : public Basis<Fourier> { // use CRTP
  ...
};

Now I wish to alias a third class template <typename T> Worker such as

template <typename BASIS, int M>
using Approx = Worker<typename BASIS::Functor<M> >;

so I can use it like

Approx<Fourier, 3>

but the aliasing gives me the error

error: template argument 1 is invalid
   30 |     Worker< typename BASIS::Functor<M> >;
      |                                        ^

Does anybody have an idea what the issue might be? The error message doesn't give more details, and using

template <int M>
using Approx = Worker<Fourier::Functor<M> >;

works fine.

I'm happy to give more details if needed.

varagrawal
  • 2,909
  • 3
  • 26
  • 36

1 Answers1

3

You also need template:

template <typename BASIS, int M>
using Approx = Worker<typename BASIS::template Functor<M> >;
//                                    ^^^^^^^^
Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • Oh snap that worked. Is the explanation that since Functor is also a template type, the compiler needs to know this exclusively? Why can't it infer it directly? – varagrawal May 24 '20 at 22:55
  • Also, I'll accept this as the answer the moment SO allows me to. – varagrawal May 24 '20 at 22:57