hello, i am having trouble with constructing an item in an item_node and using a pointer to move through a list.
here is the relevant code:
item class
Code:
class item
{
public:
item(const item& other) {power=other.power; price=other.price;
value_to_change=other.value_to_change;};
void use_item() {*value_to_change+=power;};
item(int a, int b, int &c) {power = a; price = b; value_to_change = &c;};
~item();
int get_price() {return price;};
int get_power() {return power;};
private:
int power;
int price;
int *value_to_change;
};
the item_node class
Code:
class item_node
{
public:
item_node(int a, int b, int &c, string input_name);
~item_node();
item_node *up;
item_node *down;
void use_item_from_node() {item_from_node.use_item();};
int power_from_node() {return item_from_node.get_power();};
int price_from_node() {return item_from_node.get_price();};
string get_name() {return name;}
private:
item item_from_node;
string name;
};
Code:
item_node::item_node(int a, int b, int &c, string input_name)
{
//i want to make the item_from_node to initialize here with arguments
// (a, b, c) but cant figure out how to do it
name = input_name;
};
and my sequence
Code:
void inventory::show_all_items()
{
active = ⊤ //top is the first item in the sequence
int total_items = 0;
for(; active != ⊥ total_items++) //bottom is the last item in the stack
{
cout << total_items << ": " << *active.get_name() << endl;
active = *active.down;
}
return;
}
i need to initialize my item along with the item node but dont know how,
i also need to know what is wrong with my pointer "active"
i dont want to use
Code:
item_node : public item
because then it would be simpler to just make item have a *next and a *last.
also, if i overload operator= then would it work to construct it in my item node constructor like this?
Code:
item_from_node = item x(a, b, c)
thanks for any help