【发布时间】:2010-10-01 07:15:02
【问题描述】:
C++ 无法从 typedef 或 typedef 模板化类中生成模板。我知道如果我继承并将我的类设为模板,它将起作用。
例子:
// Illegal
template <class T>
typedef MyVectorType vector<T>;
//Valid, but advantageous?
template <class T>
class MyVectorType : public vector<T> { };
这样做是否有利,以便我可以“伪造” typedef 或者有更好的方法来做到这一点?
【问题讨论】:
-
类似问题,相同答案:stackoverflow.com/questions/293988/…
-
你的第二个例子也是无效的。您必须为 MyVectorType 编写自己的构造函数,因为您不能继承它们。
标签: c++ inheritance templates typedef