gpt4 book ai didi

c++ - 使用 `using` 或其他方式显式实例化函数模板

转载 作者:行者123 更新时间:2023-11-30 03:14:34 24 4
gpt4 key购买 nike

<分区>

using类模板就像一个魅力

 template<class T,int N>
struct VecNT{ T arr[N]; };

using Vec5d = VecNT<double,5>; // doing great job!

但它似乎根本不适用于函数

 template<class T,int N>
T sumNT(T* xs){ T sum=0; for(int i=0;i<N;i++){sum+=xs[i];}; return sum; };

using sum5d = sumNT<double,5>;
// ERROR: sumNT<double,5> does not name a type

using sum5d(double* xs) = sumNT<double,5>(T* xs);
// ERROR: expected nest-name-specifier before 'sum5d'

那么如何制作sum5d作为 sumNT<double,5> 的专用/实例化别名?

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