Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么下面的代码不能编译?它说这S必须是const主要错误之一。
S
const
template <int S> class Array { int size; int items [S]; public: Array(void) :size(S){} }; void main() { int S= 30; Array <5+S> array; }
非类型模板参数必须是constexpr,即它们必须在编译时已知。因此,S必须声明为constexpr int。
constexpr
constexpr int