#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
用于声明type alias。
Type alias is a name that refers to a previously defined type (similar to typedef).
Alias template is a name that refers to a family of types.
作为variable_template应该是
template<int base, int x>
constexpr int power_v = Power<base, x>::a;
LIVE
关于c++ - 如何创建一个变量模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61683016/