程序1
#include <iostream>
std::size_t three() {
return 3;
}
int i[three()];
int main()
{
return 0;
}
程序2
std::size_t three() {
return 3;
}
int main()
{
int i[three()];
return 0;
}
这里的问题是Program 1正如预期一样会出现编译错误,错误信息如下:"error: array bound is not an integer constant before ']' token"。但我不知道为什么程序2却能够成功编译?
constexpr std::size_t three() { // ...
- πάντα ῥεῖ-Wall
和/或-pedantic
,OP 也会收到警告。 - Praetorian