typedef用于模板类

时间:2013-08-23 10:26:04

标签: c++ templates typedef

我有一个类似的模板类:

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

我在另一个类中传递了这个类对象的引用。

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

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

我正在尝试创建一个typedef别名并在函数参数中使用它,但会导致错误。 我无法模仿测试课程。

1 个答案:

答案 0 :(得分:3)

您的func成员函数必须是成员函数模板。您必须在适当的位置添加typename,因为您正在处理从属名称:

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