vendredi 29 mai 2015

unable to determine the template type even it is passed in

I have the following code:

template <typename T>
struct Data {
   struct Embed
   { 
      T t;
   };
};

struct Functor {
  template <typename T>
  void foo( typename Data<T>::Embed & e) {}
};
template <typename T, typename F>
struct Caller
{
  F f;
  template <typename T>
  void invoke() {
    typename Data<T>::Embed e;
    f.foo<T>(e); //compiler error pointed this line
   }
 };

Then I specialized the template as:

 Caller<int, Functor> c;
 c.invoke();

compiler error is : error: expected primary-expression before '>' in f.foo<T>(e); line. It seems compiler suddenly doesn't know what T is even it is specified in the template declaration on the function.

Take out the explicit specified T in foo.invoke(e) line will result could not deduce template parameter 'T'

How do I fix this? (I still want to keep the functionality that Caller can have generic functor and functor's function can be templated).

Aucun commentaire:

Enregistrer un commentaire