gpt4 book ai didi

c++ - "enum class"成员在使用时是立即实例化还是稍后实例化?

转载 作者:IT老高 更新时间:2023-10-28 23:19:05 26 4
gpt4 key购买 nike

考虑一下这个

template<typename T>
struct A {
enum class X {
V = T()
};
};

对于成员类和成员函数,C++11(和 C++03)不会实例化它们的定义,除非我们以需要它们定义的方式使用它们。 enum class 是这样吗?

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

不幸的是,我无法检查编译器,因为 C++11 刚刚推出,而且似乎一切都不可靠。

最佳答案

我想是的。 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

关于c++ - "enum class"成员在使用时是立即实例化还是稍后实例化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7787301/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com