[英]Initializing all the structure variable at once
struct LoadsForAPDLScript
{
double JntLCLoad;
double JntPPLoad;
double JntLimManLoad;
double JntLimShockLoad;
double JntOthLimTenLoad;
double JntOthLimManLoad;
double JntBPLoad;
double JntUltManLoad;
double JntUltShockLoad;
double JntOthUltTenLoad;
double JntOthUltManLoad;
};
Is there any way to initialize all the struct variable mentioned above in one line instead of initializing it one by one ? 有没有办法在一行中初始化上面提到的所有struct变量而不是逐个初始化它?
If it's C++, an empty constructor will automatically initialize all member variables of simple numerical types with zero. 如果是C ++,空构造函数将自动初始化零的简单数字类型的所有成员变量。
struct LoadsForAPDLScript {
...
LoadsForAPDLScript() {}
};
With C compatibility in mind, I'm not quite sure about whether an implicit default constructor will do this as well. 考虑到C兼容性,我不太确定隐式默认构造函数是否也会这样做。 Perhaps somebody has the C++ standard at hand (or knows it by heart), then please extend this answer. 也许有人手头有C ++标准(或者心里明白),那么请扩展这个答案。
Use memset
: 使用memset
:
LoadsForADPLScript instance;
memset(&instance, 0, sizeof(LoadsForADPScript));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.