Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;:重命名模板类_C++_Templates_Typedef - Fatal编程技术网

C++ C++;:重命名模板类

C++ C++;:重命名模板类,c++,templates,typedef,C++,Templates,Typedef,我正在寻找一些代码使它工作 template <typename T, int a, int b> class first { //not so important }; main() { first<double,1,2> sth; second<double> sth2; } 模板 头等舱 {//没那么重要 }; main() { 先做某事; 第二个sth2; } Sth2与sth的类型相同,但具有默认参数(例如) 我知道我需要一些typed

我正在寻找一些代码使它工作

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

main()
{
first<double,1,2> sth;
second<double> sth2;
}
模板
头等舱
{//没那么重要
};
main()
{
先做某事;
第二个sth2;
}
Sth2与sth的类型相同,但具有默认参数(例如) 我知道我需要一些typedef。我试过了

template <typename T>
struct help
{
typedef first<T,1,1> second;
};
模板
结构帮助
{
typedef第一秒;
};
但它只适用于附加的::(help::second),我只想将其更改为second


谢谢你的建议:)

你应该能够定义

template <typename T, int a=1, int b=2> class first
模板类优先
然后

first<double> sth2;
第一个sth2;
但是如果你真的想要两门课

template <typename T> class second : public first<T,1,1>
模板类第二:公共类第一

应该能带你去什么地方

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

如果您拥有符合C++11的编译器,您可以使用second=first编写
模板是的,这就是问题所在,我一点也不喜欢C++11:CWell,那么你会被更冗长、更不美观的解决方案所困扰。派生是个好主意(+1),但是如果没有C++11的ctor继承,您可能需要在第二个
中重复第一个的ctor。我不能使用C++11,也不能使用默认参数,因为以后我必须使用其他默认参数将f.e.设为第三个:C,并且不能将第二个改为第二个::类型。您的问题对我来说过于约束了。我想拒绝特定类存在的要求,并坚持允许以可读、简单的方式编写代码,并使用C++版本的样式。