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]);
}
2
  • store the element in some temorary variable, delete it and return the temporary variable? have you tried that ? Mar 2, 2018 at 10:03
  • right! Thank you. Could you make an answer, so I can check it as correct
    – Koroqe
    Mar 2, 2018 at 10:10

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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