Dexter
Dexter

Reputation: 1337

typedef for template class

I have a template class something like :

template< type T >
class temp {
   T val;
};

I pass the reference of this class object in another class.

template <type T>
struct def {
    typedef def<T> type;
};

class Test {
   public:
       void func(def<T>::type & obj);
};

I am trying to create a typedef alias and use it in the function parameter, but results in a error. I cannot templatize the Test class.

Upvotes: 1

Views: 673

Answers (1)

juanchopanza
juanchopanza

Reputation: 227390

Your func member function would have to be a member function template. You would have to add a typename in the appropriate place, since you are dealing with a dependent name:

class Test {
   public:
       template <typename T>           // member function template
       void func(typename def<T>::type & obj);
       //        ^^^^^^^^
};

Upvotes: 3

Related Questions