【发布时间】:2023-03-03 10:47:01
【问题描述】:
看看这段代码:
#include <iostream>
using namespace std;
using ld = long double;
template<int i>
struct A {
static_assert(false,"");
constexpr static int value = 3;
};
template<int i>
struct B {
constexpr static int value = i*i*i;
};
template<int i>
struct CheckVal {
constexpr static int value = conditional<i == 1,A,B><3>::value;
};
如果将1 传递给CheckVal,这应该会终止编译,但无论传递给CheckVal 的内容如何,我都会在编译时收到以下错误:
error: use of class template 'A' requires template arguments
constexpr static ld value = conditional<i == 1,A,B><3>::value;
这里有什么问题?我该如何解决?
【问题讨论】:
标签: c++ templates template-meta-programming