Solidity

呼叫:警告:未使用的局部變數

  • June 22, 2019

我正在嘗試編譯以下程式碼:

pragma solidity ^0.5.1;

contract MKotET1_1{
  address payable king; uint public claimPrice = 100;

  function calculateCompensation() public returns(uint) {
}

function( ) external payable {
  if (msg.value  < claimPrice) revert();
     uint compensation = calculateCompensation();
     (bool success, bytes memory returnMessage) = 
     king.call.value(compensation)("");
     require(success); 
     king = msg.sender;
  }
}

我收到以下警告消息:

> > solc MKotET_stackExchange.sol MKotET_stackExchange.sol:11:26:警告:未使用的局部變數。(bool 成功,字節記憶體 returnMessage) = king.call.value(compensation)(""); ^————————^ > > >

有人請指導我如何刪除此警告消息。

祖爾菲。

您不需要顯式聲明第二個變數聲明。你可以這樣寫:

(bool success, ) = king.call.value(compensation)("");
require(success); 

引用自:https://ethereum.stackexchange.com/questions/72124