c++ 中结构成员和类成员的默认值是什么,这些规则有何不同(例如,在类/结构/原语/等之间)?是否存在有关默认值的规则不同的情况?
What is the default values for members of a struct and members of a class in c++, and how do these rules differ (e.g. between classes/structs/primitives/etc) ? Are there circumstances where the rules about the default values differs ?
在 C++ 中,结构和类在这方面没有区别.它们都被称为类类型.
There are no differences between structs and classes in this regard in C++. They all are called just class types.
类类型的成员在一般情况下没有默认值.为了让一个类成员获得一个确定性的值,它必须被初始化,这可以通过
Members of class types have no default values in general case. In order to for a class member to get a deterministic value it has to be initialized, which can be done by
此外,所有具有静态存储持续时间的对象在程序启动时都被零初始化.
Additionally, all objects with static storage duration are zero-initialized at the program startup.
除了上述情况,类成员再次没有默认值,并且最初会包含不可预测的垃圾值.
Aside from the above cases, class members, once again, have no default values and will initially contain unpredictable garbage values.
这篇关于C++ 类成员的默认值是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 C++ 中读取和操作 CSV 文件数据?How can I read and manipulate CSV file data in C++?(如何在 C++ 中读取和操作 CSV 文件数据?)
在 C++ 中,为什么我不能像这样编写 for() 循环:In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,为什么我不能像这样编写 for() 循环: for(
OpenMP 如何处理嵌套循环?How does OpenMP handle nested loops?(OpenMP 如何处理嵌套循环?)
在循环 C++ 中重用线程Reusing thread in loop c++(在循环 C++ 中重用线程)
需要精确的线程睡眠.最大 1ms 误差Precise thread sleep needed. Max 1ms error(需要精确的线程睡眠.最大 1ms 误差)
是否需要“do {...} while ()"?环形?Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?环形?)