问题
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)
};
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.
Why?
回答1:
Microsoft did not implement support for constexpr until Visual Studio 2015.
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
来源:https://stackoverflow.com/questions/31632491/constexpr-for-sizeof-in-template-does-not-compile