开发者

Are "enum class" members instantiated immediately or later when used?

开发者 https://www.devze.com 2023-04-13 04:39 出处:网络
Consider this one 开发者_JAVA技巧template<typename T> struct A { enum class X { V = T() }; }; For member classes and member functions, C++11 (and C++03) won\'t instantiate their definition un

Consider this one

开发者_JAVA技巧template<typename T>
struct A {
  enum class X {
    V = T()
  };
};

For member classes and member functions, C++11 (and C++03) won't instantiate their definition unless we use them in a way that requires their definition. Is this true for enum class?

// valid?
A<std::string> a;

Unfortunately, I can't check compilers, since C++11 is just out of the door and everything isn't reliable yet, it seems.


I think so. 14.7.1/1

The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions or default arguments, of [...] scoped member enumerations

0

精彩评论

暂无评论...
验证码 换一张
取 消