C ++会完全擦除(或重置)结构的所有值吗? [英] C++ completely erase (or reset) all values of a struct?
本文介绍了C ++会完全擦除(或重置)结构的所有值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我只是想知道我们如何完全擦除或重置一个结构以便可以重用?
So, I was just wondering how could we completely erase or reset a structure so it could be reused?
我刚刚输入了此内容,就可以了:
I just typed this up, here you go:
typedef struct PART_STRUCT
{
unsigned int Id;
std::string Label;
} Part;
typedef struct OBJECT_STRUCT
{
std::vector< unsigned char > DBA;
std::vector< Part > Parts;
unsigned int Id;
} Object;
Object Engine;
// Initialize all members of Engine
// Do whatever with Engine
// ...
// Erase/Reset Engine value
推荐答案
您可以为其分配一个构造的临时变量:
You can just assign a constructed temporary to it:
Part my_struct;
my_struct = Part(); // reset
C ++ 11:
my_struct = {}; // reset
这篇关于C ++会完全擦除(或重置)结构的所有值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文