What's the best way to clear a mapping? Consider the following case:
struct user {
string name;
uint id;
bool valid;
bytes32 hash_id;
}
mapping (address => user) userRegister;
function clearStruct (address addr) constant returns (bool cleared) {
userRegister[addr].name = null;
userRegister[addr].id = null;
userRegister[addr].valid = null;
userRegister[addr].hash_id = null;
}
I am looking for a generic way to clear structs. the error i see right now at = null
:
Error: Expected primary expression
Anyone who could suggest, it would be greatly helpful. is the only way to make them corresponding nulls i.e. ''
for string
, 0x000… for bytes32
, false
for bool
, and 0
for int
and so on?
Best Answer
you could use
delete
to clear your map.proposition :