C ++:重命名模板化类

时间:2014-01-04 20:11:38

标签: c++ templates typedef

我正在寻找一些能让它发挥作用的代码

template <typename T, int a, int b> 
class first 
{   //not so important
};

main()
{
first<double,1,2> sth;
second<double> sth2;
}

Sth2与sth的类型相同,但具有默认参数(例如) 我知道我需要一些typedef。我试过了

template <typename T>
struct help
{
typedef first<T,1,1> second;
};

但它仅适用于额外的::(help&lt; double&gt; :: second),我只想将其更改为第二个&lt;双&GT;

感谢您的任何想法:)

2 个答案:

答案 0 :(得分:1)

你应该能够定义

template <typename T, int a=1, int b=2> class first

然后

first<double> sth2;

但如果你真的想要两个班级

template <typename T> class second : public first<T,1,1>

应该把你带到某个地方。

答案 1 :(得分:1)

使用默认参数怎么样?否则igor可能适合C ++ 11