我将我的问题简化为以下几点:
struct A {
static constexpr std::size_t f() { return 4; }
};
template<std::size_t N>
struct B : A {
alignas(A::f()) char a[N];
};
我看不出这有什么问题,但是如果我尝试使用g++
进行编译
main.cpp:9:19: error: expression 'A::f' is not a constant-expression
alignas(A::f()) char a[N];
^
main.cpp:9: confused by earlier errors, bailing out
可通过on coliru获得复制品。
发布于 2015-04-27 21:15:46
我不知道为什么原始代码不好,但这里有一个解决方法:
struct A {
static constexpr std::size_t f() { return 4; }
};
template<std::size_t ALIGN, std::size_t N>
struct C {
alignas(ALIGN) char a[N];
};
template<std::size_t N>
struct B : A, C<A::f(), N> {
};
https://stackoverflow.com/questions/29879609
复制相似问题