constexpr for sizeof in template does not compile

对着背影说爱祢 提交于 2019-12-24 11:28:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!