模板中sizeof的constexpr不会编译 [英] constexpr for sizeof in template does not compile
问题描述
在Visual C ++ 2012(C ++ 11)中,我收到错误代码
In Visual C++ 2012 (C++ 11) I am getting error for code
template <typename T, T... I>
struct structFoo
{
static const T sz = sizeof...(I); (1)
static constexpr T size = sizeof...(I); (2)
};
编译器采用行(1),但是抱怨行(2) b $ b'错误C4430:缺少类型说明符 - int。注意:C ++不支持default-int。
the compiler takes the line (1) but complains that the line (2) is an error: 'error C4430: missing type specifier - int assumed. Note: C++ does not support default-int.
为什么?
推荐答案
p> Microsoft Visual Studio 2015之前未对 constexpr
实施支持。
Microsoft did not implement support for constexpr
until Visual Studio 2015.
意味着VC ++ 2012是C ++ 11的一个实现,但这是一个大的过度简化。事实上,随着时间的推移,在多个版本中添加了各种语言和库功能;某些C ++ 11功能,不介意C ++ 14,仍然不受支持:
You imply that VC++2012 is an implementation of C++11, but that's a gross oversimplification. In fact, various language and library features were added over time across multiple versions; some C++11 features, never mind C++14, are still not supported:
- https://msdn.microsoft.com/en-us/library/hh567368.aspx#corelanguagetable
这篇关于模板中sizeof的constexpr不会编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!