gpt4 book ai didi

c++ - 如何在C++中设置数据为0?

转载 作者:太空宇宙 更新时间:2023-11-04 14:38:10 24 4
gpt4 key购买 nike

<分区>

在 C 中,我们使用 memset() 函数将数据设置为 0(不仅用于初始化)。

我的数据可以通过另一种方法更改,我想重用它然后我想在重用它之前将它设置为 0

除了 memset() 之外,还有其他方法可以在 C++ 中将数据设置为 0 吗?

class MYClass : public NameSpace::ParentClass {

private:
struct mystruct data

public:
void method();
};

void MYClass::method() {
memset(&data, 0, sizeof(data)); // it's the C way. Are there another way in C++
}

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