0

I have function, that goes to return and delete last element from array, but if I delete this element, function could return null value

function poll(Queue storage _queue) public returns(Job job) {
    require(data.length==0);
    require(_queue.length - 1 < cursorPosition);
    _queue.cursorPosition++;
    // there should be element deleting
    return (_queue.jobArray[cursorPosition - 1]);
}
  • store the element in some temorary variable, delete it and return the temporary variable? have you tried that ? – Kaki Master Of Time Mar 2 '18 at 10:03
  • right! Thank you. Could you make an answer, so I can check it as correct – Koroqe Mar 2 '18 at 10:10
1

There is no cost-effective way to do this, as the delete type behave like an assignation to the default value, thus returning a zero-like value.

As @Med Mansour told you above, store the value in a variable and then return said variable.

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.