简体   繁体   English

typedef用于模板类

[英]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. 我正在尝试创建一个typedef别名并在函数参数中使用它,但会导致错误。 I cannot templatize the Test class. 我无法模仿Test类。

Your func member function would have to be a member function template. 您的func成员函数必须是成员函数模板。 You would have to add a typename in the appropriate place, since you are dealing with a dependent name: 你将不得不增加一个typename在适当的地方,因为你正在处理一个从属名称:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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