I have a problem that when I try to delete a struct having mapping inside from its array without leaving a gap, it always says Types in storage containing (nested) mappings cannot be assigned to
.
I understand why it forbids me from doing it but I cant find a solution.
These are my structs, because I have problems with using User[] user
inside Card
struct, (I can't call something like cards[i].users[msg.sender]
) so I used mapping inside Card
struct instead:
struct User {
uint purchaseDate;
}
struct Card {
string name;
uint price;
uint lifeSpan;
mapping (address => User) users;
}
mapping(uint => Card) public cards;
I want to delete one element without leaving a gap like this:
function deleteCard(uint _id) public isOwner {
require(0 < _id || _id > types, "Card does not exist");
for (uint i = _id; i < types; i++) {
cards[i] = cards[i+1]; // error
}
}
So how to delete it like that? Or how to copy data from cards[i+1].users
to cards[i].users
? Because Solidity also does not have for loop by keys for mapping too.
Im new to Solidity, so any answer from you guys are all appreciated, thank you everyone.