1
#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;
}
4

1 回答 1

0

using用于声明类型别名

类型别名是指先前定义的类型的名称(类似于typedef)。

别名模板是指一系列类型的名称。

作为variable_template它应该是

template<int base, int x>       
constexpr int power_v = Power<base, x>::a;

居住

于 2020-05-08T15:58:17.990 回答