I thought it would be good idea to store a object of struct in a vector because I have seen it in a tutorial Tutorial but now I have a problem if I want to remove it from the vector. I want to make addressbook like contract.

I tried:

  • delete itr_address->book[i] => because of a const variable in the struct this is not working
  • itr_address->book.erase(itr_address->book.begin()+1) => some other error because of const
  • I do not know exactly what you're going to do. Please explain based on the contents of the tutorial. – smarteasy Jul 3 '18 at 14:45
  • In the tutorial you create a struct item. Later you create vector<item> in player struct. Then he shows how to add items to player: player.inventory.push_back(item{ purchased_item.item_id, purchased_item.name, purchased_item.power, purchased_item.health, purchased_item.ability, purchased_item.level_up }); now I tried to do the same thing for a test addressbook. But when i want to delete the item from the vector i get there errors because of const in the struct. – Mangooxx Jul 3 '18 at 14:52

Remove the item from the player's inventory and modify the player using players.modify.

players.modify(iterator, account, [&](auto& player) { player.inventory.erase(i); });

  • thx no more errors – Mangooxx Jul 3 '18 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.