typedef struct is ancient/C code. you do not need the typedef anymore, its a type already in modern c++. Likewise putting the variable after the } is bad form now, its making a global variable that is no longer useful (this again is 1990s era or earlier stuff that is long dead but still supported).
A class and a struct are virtually interchangeable in c++. If you explicitly make public and private blocks in your objects, then you can swap the keyword and nothing changes at all. If you rely on the default public and private, they are reversed (this is the only difference) with class default to private and struct default to public.
pointers you may want to read a bit on but in an nutshell, if you consider ram of your computer to be an array of bytes, then a pointer is an index into that array.
so
int x[10]; //represents ram
int y = 3; //represents a pointer
cout x[y]; //y is a lot like a pointer, its a position into the array.
the syntax for a pointer is nothing like the above, but conceptually, it is the same. You ask the OS for a location (or block thereof) that it is not using, it gives it to you, and when done, you give it back.
the above, in pointer lingo, then:
int *y = new int[10]; //y is still an offset into the x array (ram) its just unsaid now, it is now understood that ram exists out there somewhere and that y is offset into it.
delete[] y; //return the memory to the OS
ok, so to do this you need to keep #4 in mind and make a lot of pointers. This is an idiotic requrement, but you can do it.
start there, and try to make your object (struct or class) using pointer variables, and a constructor for it (this is where your new statements go for all those pointers) and a destructor for it (this is where all the deletes go).
a little to start:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
struct inventory
{
string *name_equipment;
double *cost;
int* quantity;
inventory()
{
name_equipment = new string;
cost = new double;
quantity = new int;
}
};
|
display should be a member function, not on the side. that is also a C concept, in c++ the function belongs with the object, in C, you have it external and may tie it with a function pointer (lets not do that today) at best or leave them decoupled (a bit troubling to organize and maintain).