First, let me say I'm not sure it was a particularly good idea which I had in the first place. So what I'm about to say is by way of clarification, but don't take it as a recommended plan.
In C++
struct
and
class
are almost the same thing. The only difference is that by default members of a struct are
public, while the default for class is
private. For historical reasons, struct tends to be used for data-only purposes, but it doesn't have to.
Myself, I tend to just use
class
for most purposes, because even those cases which may start out as plain old data often seem to lend themselves to the addition of member functions such as a constructor, or a friend function to print the contents, and so on.
So in that respect, my example was incomplete, it was missing the public keyword:
1 2 3 4 5
|
class allResources {
public:
vector<Equipment> equip;
vector<Useable> use;
};
|
and your struct then becomes equivalent.
However, I wasn't thinking quite like this:
1 2 3 4 5 6 7
|
struct Object
{
vector<Equipment> equip;
vector<useable> use;
}type;
Load_Resources(type.equip,filename);
|
What I had in mind was more like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
struct allResources
{
vector<Equipment> equip;
vector<useable> use;
};
int main()
{
allResources allres;
Load_Resources(allres, filename);
|
The struct is
declared in the global space. That just tells the compiler what it looks like. Then inside main(), an actual object of type allResources is defined with the name allres. Function Load_Resources will have the ability to access any of the member variables, in order to populate each of the vectors according to the contents of the file.
Other parts of the program (I don't know, this is your program, not mine) might have a need to access just one of the vectors, in which case it could be referred to as allres.equip and so on.
Hope that at least clarifies what I was thinking. But I don't necessarily recommend it. I had other ideas on parsing the input file which went in a completely different direction and may have been better.