#include <iostream>
using namespace std;
template<int base, int x>
struct Power {
static constexpr int a = base * (Power<base, x - 1>::a);
};
template<int base>
struct Power<base, 0> {
static constexpr int a = 1;
};
//////////////////////////////我在这里创建变量模板失败。
template<int base, int x>
using power_v = typename Power<base, x>::a;
/////////////////////////////////
int main()
{
constexpr int y = power_v<3, 2>;
cout << y;
}
using
用于声明类型别名。
类型别名是引用先前定义的类型的名称(类似于typedef)。
别名模板是指一系列类型的名称。
作为variable_template,它应该是
template<int base, int x>
constexpr int power_v = Power<base, x>::a;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句