gpt4 book ai didi

C++:重命名模板类

转载 作者:行者123 更新时间:2023-11-28 03:00:43 35 4
gpt4 key购买 nike

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

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/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com