结构,而不是清除/初始化所有数据
Structs and not clearing / initializing all data
好的,所以我想我知道我需要做什么,但我不确定如何做。
我有这个结构
struct GItemInfo{
string icon = "";
string name = "";
string subname = "";
string rarity = "";
vector<string> ToolTip;
string ToolTipFull;
bool canuse = true;
int depth = 0;
int level = -1;
int leveladjusted = -1;
int slotnum = -1;
bool isslotlocked = true;
int isslothighlighted = 0;
FVector location;
FEntityId id;
float distancetome = 0.0f;
bool istrash = false;
bool ispickuptrash = false;
bool ispickup = false;
bool empty = true;
bool operator<(const GItemInfo& a) const
{
return distancetome < a.distancetome;
}
};
我比使用
vector<GItemInfo> CurrentGearList;
要初始化它…问题是…即使在我做之后
CurrentGearList.clear();
CurrentGearList.resize(0); // Yes i know some of this is voodoo redundant.
CurrentGearList.resize(20);
ID内部的值仍然存在,并且永远不会重新初始化。因此,ID结构体只是(int,int(。。如何告诉GItemInfo结构将它们初始化为0,0。
我尝试了FEntityId id={0,0};不喜欢这样。
所以我确信我需要以某种方式在structs构造函数中工作,我只是不确定如何做到。
struct FEntityID{
int A;
int B;
FEntityID(): A(0), B(0){
}
};
通过每次创建FEntityID
的对象时为其创建默认构造函数,其int
值将用0
初始化。
如果您想控制如何为每个实例初始化结构对象,还应该为它们定义构造函数。
相关文章:
- 如何使用数据对象上的常量指针初始化类
- 如何在 malloc 内存中初始化非 POD 数据
- 内联静态数据的初始化
- 是否可以使用右值初始化数据成员?
- 构造函数正在初始化数据成员
- 初始化数据成员取决于构造函数中的条件
- openGL如何处理发送给它的空/未初始化数据?
- 如何在C 11中正确初始化数据成员
- 在具有初始化的声明中,是否可以使用对未初始化数据的引用
- 使用值初始化的数组对零初始化数据
- 在C++中,如果我们不在构造函数中初始化数据成员,那么类中数据成员的值会是多少
- 为什么我们需要构造函数 C++,我们可以通过函数(初始化数据或访问私有数据成员)来做同样的事情
- 正在初始化数据文件中的静态常量成员
- 用成员函数初始化数据成员
- 在不初始化数据的情况下调整 std::vector C++的大小<char>
- 尝试在构造函数中初始化数据成员,但失败.为什么
- 在c++中使用初始化列表初始化数据成员引用
- 如何创建一个可以初始化c++数据类型的类
- 当初始化数据类型char*和非char*时
- 代码是否被视为可移植可执行文件格式中的初始化数据,初始化数据和单元化数据之间的确切区别是什么