我有这些课程:
#include <type_traits>
template <typename T>
class A {
public:
static_assert(std::is_default_constructible_v<T>);
};
struct B {
struct C {
int i = 0;
};
A<C> a_m;
};
int main() {
A<B::C> a;
}
Run Code Online (Sandbox Code Playgroud)
编译时,a_m不是默认可构造的,而是a可构造的。
更改C为:
struct C {
int i;
};
Run Code Online (Sandbox Code Playgroud)
一切安好。
使用 Clang 9.0.0 测试。