以下是有效的C++代码,为什么不呢?
std::array<std::string, 42> a1;
std::array<int, a1.size()> a2;
Run Code Online (Sandbox Code Playgroud)
它不能在GCC 4.8中编译(在C++ 11模式下).有一个简单但不优雅的解决方法:
std::array<std::string, 42> a1;
std::array<int, sizeof(a1)/sizeof(a1[0])> a2;
Run Code Online (Sandbox Code Playgroud)
很明显,编译器可以计算出std :: array中的元素数量.为什么std :: array :: size()不是constexpr static函数?
编辑:我找到了另一种解决方法:
std::array<std::string, 42> a1;
std::array<int, std::tuple_size<decltype(a1)>::value> a2;
Run Code Online (Sandbox Code Playgroud) 我有:
constexpr bool is_concurrency_selected()const
{
return ConcurrentGBx->isChecked();//GBx is a groupbox with checkbox
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
C:\...\Options_Dialog.hpp:129: error: enclosing class of 'bool Options_Dialog::is_concurrency_selected() const' is not a literal type
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?