简体   繁体   中英

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.

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);
       //        ^^^^^^^^
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM