C++:重命名模板类

标签 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::second) 我只想将它更改为 second

感谢您的任何想法:)

最佳答案

你应该能够定义

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

然后

first<double> sth2;

但是如果你真的想要两个类

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

应该能带你去某个地方。

关于C++:重命名模板类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20926164/

相关文章:

c++ - 如何避免虚拟继承

c++ - char TypeDef 问题

c++ - 为什么类方法不能调用同名的全局函数?

C++:加入一个 WCHAR[] 数组?

c++ - 如何从 Linux 交叉编译为 32 位 Windows 可执行文件

c - 使用带有指针的 typedef const 结构

c - 如何 malloc 结构数组

c++ - 获取 IAccessible 元素的句柄

javascript - mustache.js 中的 switch 语句

templates - D:显示给定类型是否具有可比性的模板约束